Camera banking

Previous topic - Next topic

MrTAToad

How would you get a camera to bank to a certain angle - X_ROTATION with X_CAMERA wont do it.

I'm thinking of something along the lines of :


Kitty Hello


MrTAToad

#2
Do you mean X_MULTMATRIX ?  There is no X_UPVECTOR...

bigsofty

"X_CAMERAUP" is the up vector of the camera
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

MrTAToad

Unfortunately that wont work - the parameters it takes are 0 and 1, and not an angle...

bigsofty

0 to 1, x,y,z parameters are floats, the components of a single camera vector that always points up through the top of your camera...
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

MrTAToad

#6
Oh yes, the parameters are floats, but only 0.0 or 1.0 make any sense - 0.5 does nothing, for example.

Got it sorted - all 3 directions needed changing...

Hemlos


x_cameraup should be used with SIN and/or COS to get the camera to roll.

In a simple game where a 3d camera always faces a specific direction:
If you are facing the -z direction, use the circle math with x_cameraup X and Y axes.
Bing ChatGpt is pretty smart :O

MrTAToad

I managed to find an example for banking which helped, as it had the calculations needed

matchy

It's a bit tricky as I've tried. Anyone care to complete this routine?

SUB RollCamera: cameraRollAngle, cameraPosX, cameraPosY, cameraPosZ, cameraTargetX, cameraTargetY, cameraTargetX
   // x=?
   // y=?
   // z=?
   X_CAMERAUP x,y,z
ENDSUB

MrTAToad

The code I found was effectively :

Code (glbasic) Select
SUB RollCamera: cameraRollAngle, cameraPosX, cameraPosY, cameraPosZ, cameraTargetX, cameraTargetY, cameraTargetX
x = COS(cameraRollAngle) * COS(cameraRollAngle)
y = SIN(cameraRollAngle)
z = -SIN(cameraRollAngle)*COS(cameraRollAngle)   
X_CAMERAUP x,y,z
ENDSUB




matchy

Thanks for code snip. For me, that doesn't get result I'd like as the roll doesn't stay fixed. As I move the camera target, the roll is maximum (camera tilted to side) but when face the roll angle, the there is no tilt. Perhaps I'll post sample code later.

bigsofty

That's probably because your cameras pitch and yaw is still using the default up vector, the new up vector (roll) has to be taken into consideration when calculating your new viewing angle.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

MrTAToad

It worked for me because I rotated the graphics around :)

matchy

//-- X_CAMERAUP  banking solution required!

Banking_Test()

FUNCTION Banking_Test:
   // basic first person inside room scene
   LOCAL px1,py1,pz1,px2,py2,pz2,angle

   SETCURRENTDIR("Media")
   SETSCREEN 640,480,0
   LOADSPRITE "testmap.png",0
   funCreateCube(0, 0,0,0, 100,100,10) // room
   WHILE TRUE
      angle=angle+MOUSEAXIS(0)
      px1=10                     // player
      py1=10
      pz1=10
      px2=px1+(COS(angle)*10)
      py2=8
      pz2=pz1-(SIN(angle)*10)
      X_MAKE3D 1, 100, 45
      // X_CAMERAUP              // banking ?
      X_CAMERA px1,py1,pz1, px2,py2,pz2
      X_SETTEXTURE 0,0
      X_MOVEMENT px1,py1,pz1
      X_DRAWOBJ 0,-1
      SHOWSCREEN
   WEND
ENDFUNCTION

FUNCTION funCreateCube: num, x,y,z, l,w,h
   LOCAL c

   c=RGB(0xff,0xff,0xff)
   l=l*0.5
   w=w*0.5
   h=h*0.5
   X_OBJSTART num
      X_OBJADDVERTEX x-l,y+h,z+w,0,0,c
      X_OBJADDVERTEX x+l,y+h,z+w,1,0,c
      X_OBJADDVERTEX x-l,y-h,z+w,0,1,c
      X_OBJADDVERTEX x+l,y-h,z+w,1,1,c
      X_OBJNEWGROUP
      X_OBJADDVERTEX x+l,y+h,z-w,0,0,c
      X_OBJADDVERTEX x-l,y+h,z-w,1,0,c
      X_OBJADDVERTEX x+l,y-h,z-w,0,1,c
      X_OBJADDVERTEX x-l,y-h,z-w,1,1,c
      X_OBJNEWGROUP
      X_OBJADDVERTEX x-l,y+h,z+w,0,0,c
      X_OBJADDVERTEX x-l,y+h,z-w,1,0,c
      X_OBJADDVERTEX x+l,y+h,z+w,0,1,c
      X_OBJADDVERTEX x+l,y+h,z-w,1,1,c
      X_OBJNEWGROUP
      X_OBJADDVERTEX x-l,y-h,z-w,1,1,c
      X_OBJADDVERTEX x-l,y-h,z+w,0,1,c
      X_OBJADDVERTEX x+l,y-h,z-w,1,0,c
      X_OBJADDVERTEX x+l,y-h,z+w,0,0,c
      X_OBJNEWGROUP
      X_OBJADDVERTEX x+l,y-h,z-w,1,0,c
      X_OBJADDVERTEX x+l,y-h,z+w,0,1,c
      X_OBJADDVERTEX x+l,y+h,z-w,1,0,c
      X_OBJADDVERTEX x+l,y+h,z+w,0,1,c
      X_OBJNEWGROUP
      X_OBJADDVERTEX x-l,y-h,z+w,1,1,c
      X_OBJADDVERTEX x-l,y-h,z-w,0,1,c
      X_OBJADDVERTEX x-l,y+h,z+w,1,0,c
      X_OBJADDVERTEX x-l,y+h,z-w,0,0,c
      X_OBJNEWGROUP
   X_OBJEND
ENDFUNCTION