3D camera: i need a correction on camera size

how can i use the camera size for the window size:
1
2
3
4
5
6
7
camera1.size.Height = Me.ScaleHeight + 100
    camera1.size.Width = Me.ScaleWidth
    camera1.Position.X = Me.ScaleWidth / 2
    camera1.Position.Y = -Me.ScaleHeight / 2
    camera1.Position.Z = -300
    camera1.size.ZDepth = 4000
    camera1.size.distance = 100

and heres the function that i test if the point is inside the camera:
1
2
3
4
5
6
7
8
9
Private Function IsOnCamera(VerticePosition As Position3D, CameraPosition As Position3D, CameraSize As Size3D) As Boolean
    If (((VerticePosition.Z) >= CameraPosition.Z) And ((VerticePosition.Z) <= (CameraPosition.Z + CameraSize.ZDepth)) _
    And (((VerticePosition.Y) >= CameraPosition.Y) And ((VerticePosition.Y) <= (CameraPosition.Y + CameraSize.Height))) _
    And (((VerticePosition.X) >= CameraPosition.X) And ((VerticePosition.X) <= (CameraPosition.X + CameraSize.Width)))) Then
        IsOnCamera = True
    Else
        IsOnCamera = False
    End If
End Function

true... now seen these code, i mean doing these topic, i see 1 problem:
the CameraPosition.X is the center of Width, instead zero, so i'm doing wrong.. but like i said i need more corrections and understand it more..
Visual Basic?
ok... again i fail... sorry.
heres the code:
1
2
3
4
5
6
7
camera1.size.Height = FormHeight + 100
    camera1.size.Width = FormWidth
    camera1.Position.X = FormWidth / 2
    camera1.Position.Y =-FormHeight / 2
    camera1.Position.Z = -300
    camera1.size.ZDepth = 4000
    camera1.size.distance = 100

1
2
3
4
5
6
7
8
9
10
11
12
13
boolean IsOnCamera(Position3D VerticePosition, Position3D CameraPosition, Size3D CameraSize)
    If (((VerticePosition.Z) >= CameraPosition.Z) &&((VerticePosition.Z) <= (CameraPosition.Z + CameraSize.ZDepth)) _
    && (((VerticePosition.Y) >= CameraPosition.Y) &&((VerticePosition.Y) <= (CameraPosition.Y + CameraSize.Height))) _
    &&(((VerticePosition.X) >= CameraPosition.X) && ((VerticePosition.X) <= (CameraPosition.X + CameraSize.Width)))) 
{
        IsOnCamera = true
  }
  else
{
        IsOnCamera = false
}
 }
}

i'm sorry for something again.
i need review these code, because i get empty lines, because of these code:
https://imgur.com/a/zYJHWNj
see the image bottom... we seen yellow lines.. that yellow lines is the empty place... they can be avoided just changing the camera size\position.. but i need understand more about it
So now you show a picture on imgur of a blank black screen on imgur.
try again please.. yesterday, i didn't upload it, because of loading page problems
Generally the screen view will simply be a view of what the camera sees so the only test is whether the 3d point is in the camera field of view or not.

That means you use camera coordinates (transformed from global coordinates) If z is the depth of field direction then ignore it because it will always be in the view.

For x and y simple geometry determines whether they are in the field of view of the camera by knowing the camera lens angle property and the z coordinate
in these case the camera size is the window size... but seems not right, because i'm not controlling the position objects :(
in these case the camera size is the window size... but seems not right, because i'm not controlling the position objects :(


Both of those statements tell me you have forgotten or simply don't understand the concepts of local(camera) coordinates, global(world) coordinates and screen(view) coordinates and the transforms(matrices) involved to go from one to another.

Somehow or other, certainly not by magic, you know the point's xyz (global) coordinates, and the position and direction of the camera. Both are (often but not always as in some other projects) independent of each other so it is no surprise the camera doesn't move the object.

Unless you have a clear picture of what the coordinate systems and transforms mean, you are unfortunately wasting your time and probably keep trying random but incorrect changes.

The screen view is essentially and simply a scaled view of what the camera sees, subject to clipping(maybe) and probably aspect ratios.

PS I have now seen your yellow image.

The situation is exactly as I said.

Change the field of view on the camera and the rest follows.

or,

Rotate the camera to the left and the road/runway should centre up on the screen. Keep rotating until the road/runway disappears altogether - just like magic ...
everytime the form is resized, the camera size is changed... the camera size is the form size.
so heres the code that i use for convert the 3D to 2D coordenates:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public POINTAPI ConvertPositon3DTo2D(Position3D Position, Size3D World3DSize) {
        POINTAPI ConvertedPosition;
        long PosZZDepth;
        double Width;
        double Height;
        // sum Z position with cam world distance:
        PosZZDepth = (Position.Z + World3DSize.distance);
        if ((PosZZDepth == 0)) {
            PosZZDepth = 1;
        }
        
        // avoiding division by zero
        // getting center of the screen center:
        // If (World3DSize.Width = 0) Then World3DSize.Width = 1 'avoiding division by zero
        Width = (World3DSize.Width / 2);
        // If (World3DSize.Height = 0) Then World3DSize.Height = 1 'avoiding division by zero
        Height = (World3DSize.Height / 2);
        // avoid drawing on back of the camera:
        if ((PosZZDepth <= World3DSize.distance)) {
            PosZZDepth = 1;
            // World3DSize.distance = 1
        }
        
        // convert 3D(X, Y, Z) to 2D(X,Y):
        // ConvertedX = (ActualX * CamDistance /(CamDistance + ZPosition)) + HalfCenterOfWidth
        // ConvertedY = (ActualY * CamDistance /(CamDistance + ZPosition)) + HalfCenterOfHeight
        ConvertedPosition.X = ((Position.X 
                    * (World3DSize.distance / PosZZDepth)) 
                    + Width);
        ConvertedPosition.Y = ((Position.Y 
                    * (World3DSize.distance / PosZZDepth)) 
                    + Height);
        return ConvertedPosition;
    }

the world size is the camera size.. but i will review the code and test more... thank you so much for all.
i think the conversion function is ok... but i accept be corrected.
thank you
Last edited on
everytime the form is resized, the camera size is changed... the camera size is the form size.
so heres the code that i use for convert the 3D to 2D coordenates:
... the world size is the camera size..


Hopefully with these couple of statements and earlier comments you are beginning to get a clear picture that you are, with all due respect, confused.

The normal, well established practice for using a screen to display a camera view of a 3d object in the real world is to take it in 3 independent, transform based steps.

To that end, I suggest you read up some theory and in that process learn about matrix transform:
a) http://math.hws.edu/graphicsbook/index.html
b) http://www.cse.psu.edu/~rtc12/CSE486/lecture12.pdf
There is nothing like a camera size. It is just a 3d point to calculate the projection, i.e. from 3d to 2d. See:

https://en.wikipedia.org/wiki/3D_projection
There is nothing like a camera size.

Well that was a spellbindingly useful contribution from @coder777. It doesn't even make sense as a simian grunt let alone any sort of language even remotely like English.
againtry (1544): the transformation formula from 3D to 2D is:

X = X/Z
Y = Y/Z

but, on Z, we add the camera distance.
until here fine... but, on PDF, they said:
X = f X/Z
what is 'f'? is the zoom or something?.. but the zoom is represented by Z distance
and the Matrix is new to me.

Coder777: thanks for the link too.

thank you so much for all to all
f is the focal length as described and shown in the first couple of pages in the lecture pdf.
thank you so much for all
edit: after test it more, i found the problem... the 'f' but, i must add it on camera distance for draw it without empty lines....
please review these function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public POINTAPI ConvertPositon3DTo2D(Position3D Position, Size3D World3DSize) {
        POINTAPI ConvertedPosition;
        long PosZZDepth;
        double Width;
        double Height;
        // sum Z position with cam world distance:
        PosZZDepth = (Position.Z + World3DSize.distance);
        if ((PosZZDepth == 0)) {
            PosZZDepth = 1;
        }
        
        // avoiding division by zero
        // getting center of the screen center:
        // If (World3DSize.Width = 0) Then World3DSize.Width = 1 'avoiding division by zero
        Width = (World3DSize.Width / 2);
        // If (World3DSize.Height = 0) Then World3DSize.Height = 1 'avoiding division by zero
        Height = (World3DSize.Height / 2);
        // avoid drawing on back of the camera:
        if ((PosZZDepth <= World3DSize.distance)) {
            PosZZDepth = 1;
            // World3DSize.distance = 1
        }
        
        // convert 3D(X, Y, Z) to 2D(X,Y):
        // ConvertedX = (ActualX * CamDistance /(CamDistance + ZPosition)) + HalfCenterOfWidth
        // ConvertedY = (ActualY * CamDistance /(CamDistance + ZPosition)) + HalfCenterOfHeight
        ConvertedPosition.X = ((Position.X 
                    * (World3DSize.distance / PosZZDepth)) 
                    + Width);
        ConvertedPosition.Y = ((Position.Y 
                    * (World3DSize.distance / PosZZDepth)) 
                    + Height);
        return ConvertedPosition;
    }

i add the cam distance(i belive that is the 'f') to Z position.
is these correct or i must do:
x'=f*(X/Z)
???
when i compare if the vector is on cam, i added the cam distance('f') and these help me avoiding the empty lines... maybe i need a little more theory correction for i understand it.
Last edited on
I don't have VB.

But you can easily check your code in two ways:
1. Try it out on a 3D filled triangle.
2. Check your code against the pdf material I gave you - I suggest you use similar/simple variable names.

Also, mixing long and double is not a good idea - double throughot for coordinates is best in order to ensure you are not accidentally building in integer division truncation errors.

Topic archived. No new replies allowed.