Rotate camera

Previous topic - Next topic

Moru

Hello!

I was wondering how to rotate the camera. X_ROTATION 10, 1,0,0 before I place the camera doesn't work, it just exits when I try to start the program, no error code.

I'm trying to create a bike-sim (very simple one ofcourse :-) I can drive around the landscape but I can't tilt the camera to recreate the lean into curves feeling of driving a bike

Kitty Hello

OK, there's 2 ways. First way is to position the camera at 0,0,0, then use X_MOVEMENT, X_ROTATION for camera placment/direction and a X_PUSHMATRIX, draw all objects, X_POPMATRIX.
The other way ( which I prefer ) is to use X_CAMERA, where you give the look-at point.

If you just want to rotate the camera it's this:
dx = -sin(phi)
dz =  cos(phi)
x_camera cx,cy,cz,  cx+dx, cy, cz+dz

HTH,
-Gernot

Moru

I see I was a bit unclear. I have the rotation forward and left figured out, what I can't get working is rolling the camera angle so I can make the horizon diagonal. If you think of a plane banking left or right while turning.

So I have to rotate everything else and leave the camera at 0,0,0? How does that work with measuring the height of the heightfield we are traveling on? X_COLLISIONRAY works just fine now but I guess I could do it faster with some math.

Kitty Hello

If you have a heightfield, there's faster ways than X_COLLISIONRAY.
For the camera thingy...
Code (glbasic) Select
dx = cos(phi) * cos(psi)
dy =                sin(psi)
dz = -sin(phi)*cos(psi)
where psi is angle in XZ, psi is the up-down angle.

Moru

My wife will translate to german tomorrow, I hope she can make it more clear than I can in english :-)

Kitty Hello


Moru



This is me taking of from Kathmandu airport, banking right after takeoff. How do I do this without having to rotate the whole heightfield? :-)

The explanation you gave is only for horizontal turning left/right and up/down. I'm not sure how to make the camera follow thru a curve like this.

Kitty Hello

OK. You need X_UPVECTOR before you call X_CAMERA.
Basically it's the best to calculate the position/up/front/right vectors for the camera before you start. Then do:
Code (glbasic) Select
X_UPVECTOR ux,uy,uz
X_CAMERA px,py,pz, px+fx,py+fy,pz+fz
Where ux,uy,uz is upvector, px,py,pz = camera position, fx,fy,fz=front vector (facing direction)

Moru

GLBasic says it doesn't know X_UPVECTOR, do you mean X_CAMERAUP? I will try that out if I can figure out how to know what direction to tilt it :-)

Kitty Hello

Sure. X_CAMERAUP. Doh! :D