Qbasicnews.com

Full Version: Rotating Camera in 3d
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Alright i think this is a simple question about 3d.
I created a 3d cube in witch you can move in and out of using the arrow keys to adjust x and y and + and - to adjust the z of the camera. Now what I am wondering about is how to make it apear as if you are turning the camera or rotating it in a circle so you can look at all the sides of the box.
You need to use the usual ways of rotation used in 2D using SIN and COS function. For example to make the cube looking like you are walking around it, you will need to do a rotation on the X and Y axis keeping Z unchanged (I assumed that Z points upwards).
Yep something like this
Code:
.....
.....
rz = SQR(xc ^ 2 + yc ^ 2)

a = ATN(yc / xc)
IF xc < 0 THEN a = a + 3.14

x01 = rz * COS(a + alpha)            'X rotation of the point
y01 = rz * SIN(a + alpha)           '  Y
z01 = zc 'rz1 * SIN(az)             '    Z the same

x1 = x01 * COS(Gamma) + z01 * SIN(Gamma) 'proection on the screen
y1 = y01 * SIN(beta) + z01 * COS(beta)
..........
.........
Transpose your object matrix and transform your vertices as usual.

It's that easy with matrices.