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 :
(http://t0.gstatic.com/images?q=tbn:CODEvja6n6pkTM:http://imag.malavida.com/mvimgbig/download/afterburner-3d-4168-1.jpg)
X_UPVECTOR.
Do you mean X_MULTMATRIX ? There is no X_UPVECTOR...
"X_CAMERAUP" is the up vector of the camera
Unfortunately that wont work - the parameters it takes are 0 and 1, and not an angle...
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...
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...
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.
I managed to find an example for banking which helped, as it had the calculations needed
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
The code I found was effectively :
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
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.
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.
It worked for me because I rotated the graphics around :)
//-- 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