Hello!
I am creating custom 3D engine from scratch and I am having trouble with rotating.
To draw particular 3D model you need to store every vertex data in some kind of list,
then because computation rotation of every vertex individually is ineffective I can simply rotate camera in position so that model looks it's rotated then I just have to save calculated screen positions , and repeat that action for every object in scene.
Every model which is imported is located in origin(0,0,0)
and the information I have is cameraX , cameraY, cameraZ, cameraRotationX(angle), cameraRotationY,cameraRotationZ
then objectX , objectY, objectZ, objectRotationX, objectRotationY and objectRotationZ (when model it's imported we consider it's pointing at +Z axis)
And this is how I am calculating screen position of some vertex accordion to camera position and rotation:
Set Ver1(a)(b)(c) is same as ~GetX1=a; ~GetY1=b; ~GetZ1 = c;
Then to convert it to screen I use screenX=~GetX1/~GetZ1*FieldOfView and screenY=~GetY1/~GetY1*FieldOfView (FieldOfView is custom number and it's constant)
So to rotate object I can't simply rotate every of it's numerous vertices but I need to rotate and move camera in that way so the object looks rotated.
For real world example imagine a car which is pointing at you and you are watching at that car and you want to see side of that car, logically you won't rotate whole car it will be physically demanding , but you will change your position to be at the left of the car and rotate you by 90 degrees (at y axis).
Now in this case everything is same expect you can fly and you want to see it from below, from side ,from top ,half bottom -half side etc.
(from angle of (objectRotX,objectRotY,objectRotZ))
I tried to use same Vertex-> Screen funtion(as upper function) but to rotate camera around (0,0,0) and this is not working because that rotation is not rotated(and I don't know what I am doing basically )
for example if you want to watch the top of object and you are currently watching side you will rotate wrong way.
This image may help you to help me
(xs,ys,zs) is camera position and it's pointing to somewhere(cameraRotX, cameraRotY,cameraRotZ ) and Vt is always pointing at same (0,0,1)
So I need to calculate (x', y' z') and (cameraRotX' , cameraRotY', cameraRotZ') so the Vector Vt looks it's rotated from view camera for(objectRotX,objectRotY,objectRotZ)
(and (x' y' z') have the same distance from origin as (x,y,z)
I am creating custom 3D engine from scratch and I am having trouble with rotating.
To draw particular 3D model you need to store every vertex data in some kind of list,
then because computation rotation of every vertex individually is ineffective I can simply rotate camera in position so that model looks it's rotated then I just have to save calculated screen positions , and repeat that action for every object in scene.
Every model which is imported is located in origin(0,0,0)
and the information I have is cameraX , cameraY, cameraZ, cameraRotationX(angle), cameraRotationY,cameraRotationZ
then objectX , objectY, objectZ, objectRotationX, objectRotationY and objectRotationZ (when model it's imported we consider it's pointing at +Z axis)
And this is how I am calculating screen position of some vertex accordion to camera position and rotation:
Then to convert it to screen I use screenX=~GetX1/~GetZ1*FieldOfView and screenY=~GetY1/~GetY1*FieldOfView (FieldOfView is custom number and it's constant)
So to rotate object I can't simply rotate every of it's numerous vertices but I need to rotate and move camera in that way so the object looks rotated.
For real world example imagine a car which is pointing at you and you are watching at that car and you want to see side of that car, logically you won't rotate whole car it will be physically demanding , but you will change your position to be at the left of the car and rotate you by 90 degrees (at y axis).
Now in this case everything is same expect you can fly and you want to see it from below, from side ,from top ,half bottom -half side etc.
(from angle of (objectRotX,objectRotY,objectRotZ))
I tried to use same Vertex-> Screen funtion(as upper function) but to rotate camera around (0,0,0) and this is not working because that rotation is not rotated(and I don't know what I am doing basically )
for example if you want to watch the top of object and you are currently watching side you will rotate wrong way.
This image may help you to help me
(xs,ys,zs) is camera position and it's pointing to somewhere(cameraRotX, cameraRotY,cameraRotZ ) and Vt is always pointing at same (0,0,1)
So I need to calculate (x', y' z') and (cameraRotX' , cameraRotY', cameraRotZ') so the Vector Vt looks it's rotated from view camera for(objectRotX,objectRotY,objectRotZ)
(and (x' y' z') have the same distance from origin as (x,y,z)