Sometimes I want to bang my head against the wall because I can't even really figure out what it is I'm trying to accomplish lol.
Anyhow - take a look at this. It orbit pans with the arrow keys or the mouse (RTS style) as it moves near the edge of the screen.
Rem Project: Orbit Experimentation 4
Rem Created: 1/5/09 8:29:46 PM
Rem ***** Jon L. *****
Set Display mode 1024,768,32
MAKE CAMERA 1
SET CAMERA VIEW 1,600,1,1020,300
COLOR BACKDROP 0,rgb(0,0,0)
COLOR BACKDROP 1,rgb(0,0,0)
SYNC ON
Make Matrix 1,400,400,20,20
position matrix 1,-200,0,-200
`True Target Object
make object cube 1, 10
position object 1,0,5,20
`Dummy Object
Make Object Cube 2,5 ` note make dummy size 10 to see it during render
position object 2,0,5,20
Dummy = 2
`Camera Object
Make Object Cube 3,5
Color Object 3,rgb(0,0,255)
position camera 0,0,30,-50
Position Camera 1,0,100,0
Point_Camera(0,1)
Point_Camera(1,1)
OrbitPanSpeed# = .05
`*** Main Loop ***
Do
`Draw Frame Around View
Line_Box(RGB(255,0,0),600,1,1020,300)
`Set Ink Color and Print the Frames Per Second
Ink RGB(255,255,255),0
Set Cursor 10,20
Print "FPS:"+str$(screen fps())
CameraOrbitObject(0,Dummy,.2)
sync
loop
`3D Functions
Function Center_Object(Object,Object_Target)
`Function used to simplify centering an object on another object.
Position Object (Object),Object Position X(Object_Target),Object Position Y(Object_Target), Object Position Z(Object_Target)
EndFunction
Function Point_Camera(Camera,Object_Number)
`Function used to simplify pointing a camera at an object.
Point Camera Camera, Object Position X(Object_Number),Object Position Y(Object_Number),Object Position Z(Object_Number)
Endfunction
Function Point_Object(Object_Number_1,Object_Number_2)
`Function used to simplify pointing objects at one each other.
Point Object Object_Number_1, Object Position X(Object_Number_2),Object Position Y(Object_Number_2),Object Position Z(Object_Number_2)
Endfunction
Function Center_Camera(Camera,Object)
`Function used to simplify centering a camera on an object.
Position Camera (Camera),Object Position X(Object),Object Position Y(Object), Object Position Z(Object)
EndFunction
`2D Functions
Function Line_Box(Color,X1,Y1,X2,Y2)
`Function used for drawing a (1) pixel line box at the specified color and coordinates.
`line 599,0,599,300
Ink Color,0
`Top Left to Bottom Left
line X1,Y1,X1,Y2
`Bottom Left to Bottom Right
line X1,Y2,X2,Y2
`Bottom Right to Top Left
line X2,Y2,X2,Y1
`Top Right to Top Left
line X2,Y1,X1,Y1
EndFunction
Function CameraOrbitObject(Camera, Dummy, OrbitPanSpeed#)
`This is a function based on code that I found on the DBP Forums by "Rye"
`I modified it to work with RTS style mouse panning
cax#=object angle x(Dummy)
cay#=object angle y(Dummy)
cx#=object position x(Dummy)
cy#=object position y(Dummy)
cz#=object position z(Dummy)
if leftkey()=1 or mousex() < screen width() / 4
cay#=wrapvalue(cay#-OrbitPanSpeed#)
Endif
if rightkey() = 1 or mousex() > screen width() - screen width() / 4
cay#=wrapvalue(cay# + OrbitPanSpeed#)
endif
if upkey()=1 or mousey() < screen height()/4
cax#=wrapvalue(cax#-OrbitPanSpeed#)
endif
if downkey()=1 or mousey() > screen height() - screen height()/4
cax#=wrapvalue(cax#+OrbitPanSpeed#)
endif
if cax# > 270 then cax# = 270
if cax# < 90 then cax# = 90
yrotate object Dummy,cay#
xrotate object Dummy,cax#
dist#=50*cos(cax#)
oy#=newyvalue(cy#,cax#,50)
ox#=newxvalue(cx#,cay#,dist#)
oz#=newzvalue(cz#,cay#,dist#)
Position Camera Camera,ox#,oy#,oz#
Position Object 3,ox#,oy#,oz# ` Remove this as it represents a camera object
Point_Camera(Camera,Dummy)
Point_Object(3,1) ` Remove this as it represents a camera object
Endfunction
This works kind of with a dummy object that rotates and a main cube that is static. (I know I'm sloppy
) (There is also a blue object that represents the camera.)
I'm getting confusted trying to figure out what should actually happen in the ship were rotating. I guess the orbit position should remain the same but the camera should rotate with the ship so that it remains in the same offset position.
I'm going to experiment with your code now. You've been a great help thus far. Can't thank you enough.
Wannabe Game Designer. Wannabe Programmer. Expert Dreamer.
Long Island Amateur Game Development Group http://www.meetup.com/LIAGDG/