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..
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
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 :(
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.
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:
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
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.
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.
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:
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.
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.