Posted: 15th Jun 2007 2:01
right now, i have it so mouse controls camera X and Y when right clicking, and mouseclick or WASD controls camera movement.

the camera does 'walk around' the planetoid, so i have made progress

however, the 'top' is always the global 'upwards' and 'bottom' is always the global 'downwards'. i want to manipulate the Z angle of the character, depending on his position around the planetoid, so that it always looks like 'up' is away from the planet and 'down' is towards the ground

this is what i don't know how to do, please help

here is the current code, no media required

+ Code Snippet
REM Ini
sync on
sync rate 60
set camera range 1.0, 99999.9

REM Var
global cam_spd as float:	cam_spd = 1.0
global cam_hgt as float:	cam_hgt = 10.0

global obj_cam

REM Load
make_test_level()

REM Char
obj_cam = 3
make object sphere obj_cam, 20.0

REM Main
do
	set cursor 0,0
	
	display_camera_readouts()
	
	move_char_with_WASD()
	orient_char_with_mouse()
	
	bound_char_around_origin(1, 100)
	
	set_camera_to_camera_object()
	sync
loop

function display_camera_readouts()
	print "Cam FPS: "; screen fps()
	print "Cam X: "; camera position x()
	print "Cam Y: "; camera position y()
	print "Cam Z: "; camera position z()
	print "Cam Ang X: "; camera angle x()
	print "Cam Ang Y: "; camera angle y()
	print "Cam Ang Z: "; camera angle z()
endfunction

function make_test_level()
	
	make object sphere 1, 200, 16, 16
	make object cube 2, 1
	position object 1, 500, 0, 0
	position object 2, 0, 0, 0
	
endfunction

function move_char_with_WASD()
	
	if keystate(17) or mouseclick() = 3
		move object obj_cam, cam_spd
	endif
	if keystate(31)
		move object obj_cam, -cam_spd
	endif   
	if keystate(30)
		position object obj_cam, newxvalue(object position x(obj_cam), object angle y(obj_cam)-90.0, cam_spd), object position y(obj_cam), newzvalue(object position z(obj_cam), object angle y(obj_cam)-90.0, cam_spd)
	endif
	if keystate(32)
		position object obj_cam, newxvalue(object position x(obj_cam), object angle y(obj_cam)+90.0, cam_spd), object position y(obj_cam), newzvalue(object position z(obj_cam), object angle y(obj_cam)+90.0, cam_spd)
	endif
	
endfunction

function bound_char_around_origin(obj as integer, r as float)
	local d as float
	local x as float
	local y as float
	local z as float
	local ang_x as float
	local ang_y as float
	local ang_z as float
	
	REM Get object to rotate around's position
	x = object position x(obj)
	y = object position y(obj)
	z = object position z(obj)
	
	REM Get camera object angles
	ang_x = object angle x(obj_cam)
	ang_y = object angle y(obj_cam)
	ang_z = object angle z(obj_cam)
	
	REM Point to object
	point object obj_cam, x, y, z
	REM Make sure at least one radius away
	move object obj_cam, -r
	REM Get distance from self to object to rotate around
	d = intersect object(1, object position x(obj_cam), object position y(obj_cam), object position z(obj_cam), x, y, z)
	REM Move object so its at surface
	move object obj_cam, d
	REM Move back so its 'cam-height' away from surface
	move object obj_cam, -cam_hgt
	
	REM Return camera object angles
	rotate object obj_cam, ang_x, ang_y, ang_z
	
endfunction

function orient_char_with_mouse()
	local mx as float
	local my as float
	
	REM Var
	mx = mousemovex() / 5.0
	my = mousemovey() / 5.0
	
	if mouseclick() > 1
		`hide moues while looking around
		hide mouse
		position mouse 512, 384
		`turn camera object
		xrotate object obj_cam, wrapvalue(object angle x(obj_cam) + my)
		yrotate object obj_cam, wrapvalue(object angle y(obj_cam) + mx)
	
		if keystate(44)
			zrotate object obj_cam, wrapvalue(object angle z(obj_cam) + 1.0)
		endif
		if keystate(45)
			zrotate object obj_cam, wrapvalue(object angle z(obj_cam) - 1.0)
		endif
	else
		show mouse
	endif
	
endfunction

function set_camera_to_camera_object()
	position camera object position x(obj_cam), object position y(obj_cam), object position z(obj_cam)
	rotate camera object angle x(obj_cam), object angle y(obj_cam), object angle z(obj_cam)
endfunction
 
Posted: 15th Jun 2007 2:34
I would do it with two spheres.

One sphere is the plant the other sphere is invisible, stick the man to the invisible sphere as a limb, the you can contol the man by rotating the sphere. His feet will then always face the floor.

Or just use one sphere for the planet and instead of moveing the man move the planet to show movement.

Or use Dark Physics and do it properly with gravity
Posted: 15th Jun 2007 2:50
i can't just move the planet because i want to have multiple planets

i do have dark physics. i don't see how it'd help with camera orientation
Posted: 15th Jun 2007 8:27
Maybe something along these lines?

+ Code Snippet
Sync On:Sync Rate 60:Autocam Off
Set Camera Range .01,3000
`Color Backdrop 0

null=Make Vector3(1)

Type vectors
   x as float
   y as float
   z as float
Endtype

Type attributes
   p as vectors
   a as vectors
   v as vectors
   s as vectors
Endtype

Global temp as attributes
Global speed as float
Dim Roid(500) as attributes
speed#=.01

Splotch(150,20)
Ink Rgb(0,0,200),0
Box 0,0,270,270
Sprite 1,0,0,1
Lock Pixels
For i = 1 to 200
   Rotate Sprite 1,rnd(360)
   Set Sprite Diffuse 1,0,rnd(100)+50,0
   Paste Sprite 1,rnd(180)+13,rnd(150)+43
Next i
Unlock Pixels
Blur Bitmap 0,3
Get Image 2,4,4,260,260,1
Ink Rgb(255,255,255),0

Make Object Sphere 1,380,180,180
Texture Object 1,2
Set Object Diffuse 1,Rgb(255,255,255)
Set Object Specular 1,Rgb(255,255,50)
Set Object Specular Power 1,200

Splotch(150,20)
Ink Rgb(0,0,0),0
Box 0,0,270,270
Sprite 1,0,0,1
Lock Pixels
c=rnd(50)+200
Set Sprite Diffuse 1,c,c,c
For i = 1 to 100
   Rotate Sprite 1,rnd(360)
   Paste Sprite 1,rnd(180)+13,rnd(150)+43
Next i
Unlock Pixels
Blur BItmap 0,3
Get Image 3,0,0,256,256,0
Ink Rgb(255,255,255),0

Make Object Sphere 2,382,120,120
Texture Object 2,3
Ghost Object On 2
Set Object Light 2,0
Fade Object 2,90




Splotch(150,20)
Ink Rgb(35,25,15),0
Box 0,0,270,270
Sprite 1,0,0,1
Lock Pixels
For i = 1 to 200
   Rotate Sprite 1,rnd(360)
   c=rnd(50)+25
   Set Sprite Diffuse 1,c+10,c,c-10
   Paste Sprite 1,rnd(256),rnd(150)+43
Next i
Unlock Pixels
Get Image 100,4,4,260,260,0
Ink Rgb(255,255,255),0

Make Object Sphere 100,4,5,5
Make Mesh From Object 1,100
Delete Object 100
Make Object triangle 100,0,0,0,0,.01,0,0,0,0
Add Limb 100,1,1
Offset Limb 100,1,0,200,0
Rotate Object 100,Rnd(360),Rnd(360),Rnd(360)
Roid(0).s.x=(rnd(20.0)/10.0)-1.0
Roid(0).s.y=(rnd(20.0)/10.0)-1.0

Texture Limb 100,1,100
Set Object Diffuse 100,Rgb(200,200,200)
Set Object Ambience 100,Rgb(200,200,180)
Set Object Emissive 100,rgb(25,25,23)
Set Object Specular 100,rgb(50,50,10)
Set Object Specular Power 100,30

For i = 1 to Array Count(Roid(0))
   Clone Object 100+i,100
   Rotate Object 100+i,Rnd(360),Rnd(360),Rnd(360)
   Roid(i).s.x=(rnd(20.0)/10.0)-1.0
   Roid(i).s.y=(rnd(20.0)/10.0)-1.0
Next i

Make Object triangle 3,0,0,0,0,.01,0,0,0,0
Make Mesh From Object 1,3
Add Limb 3,1,1
Offset Limb 3,1,0,200,0
Hide Object 3

`Lock Pixels
Create Bitmap 1,512,512
Ink 0,0
Box 0,0,512,512
For i = 0 to 2000+rnd(1000)+Rnd(1000)
   ink rgb(rnd(55)+200,rnd(55)+200,rnd(55)+200),0
   Dot rnd(512),Rnd(512)
Next i
`Unlock Pixels
Ink rgb(255,255,255),0
Get Image 1,0,0,512,512,0
Delete Bitmap 1
Set Current Bitmap 0

Make Object Cube 5,2000
Texture Object 5,1
Set Object Light 5,0
Set Object Emissive 5,rgb(100,100,100)
Set Object Cull 5,0

Ink Rgb(255,255,0),0
Box 0,0,128,128
Get Image 6,0,0,128,128,0
Ink rgb(255,255,255),0

For i = 6 to 9
   Make Object Sphere i,-540+i*100,12,12
   Texture Object i,6
   Position Object i,500,60,400
   Set Object Emissive i,Rgb(255,255,255)
   Ghost Object On i
   Fade Object i,60-i*2
Next i
Ghost Object Off 6
Set Object Light 6,0
Fade Object 6,255


Hide Light 0


Make Light 1
Color Light 1,255,255,50
Position Light 1,500,60,400
Set Light Range 1,2000
Set Ambient Light 25



click=0
Do
   Turn Object Left 1,.002
   Turn Object Left 2,.005
   Turn Object Right 5,.002
   Pitch Object Down 3,(Upkey())*.05
   Turn Object Left 3,(LeftKey()-RightKey())*1.0
   Position Camera LPosX (3,1), LPosY (3,1), LPosZ (3,1)
   Rotate Camera LDirX (3,1), LDirY (3,1), LDirZ (3,1)
   Move_Asteroids()
   If MouseClick()=1 and click=0
      click = 1
      Make_Bullet()
   Endif
   click=MouseClick()
   Move_Bullets()
   Set Cursor 0,0
   Print "FPS: ";Screen FPS()
   Sync
Loop



Function Move_Asteroids()
   For i = 0 to Array Count(Roid(0))
      If Object Visible(100+i)
         Pitch Object Down 100+i,speed
         Rotate Limb 100+i,1,LAngx (100+i,1)+Roid(i).s.x , LAngY (100+i,1)+Roid(i).s.y , LAngZ (100+i,1)+Roid(i).s.z
      Else
         Pitch Object Down 100+i,speed
         r#=Get_Limb_Distance(100+i,1,3,1)
         If r#>150
            Show Object 100+i
            speed=speed+.0002
         Endif
      Endif
   Next i
Endfunction



Function Record_Rotation(ObjectID)
   temp.a.x = AngX (ObjectID)
   temp.a.y = AngY (ObjectID)
   temp.a.z = AngZ (ObjectID)
Endfunction

Function Record_Position(ObjectID)
   temp.p.x = PosX (ObjectID)
   temp.p.y = PosY (ObjectID)
   temp.p.z = PosZ (ObjectID)
Endfunction

Function Record_Camera_Rotation()
   temp.a.x = CAngX ()
   temp.a.y = CAngY ()
   temp.a.z = CAngZ ()
Endfunction

Function Record_Camera_Position()
   temp.p.x = CPosX ()
   temp.p.y = CPosY ()
   temp.p.z = CPosZ ()
Endfunction


Function Get_Planet_Distance(ObjectID)
   Set Vector3 1,PosX (ObjectID)- PosX (1),PosY (ObjectID)-PosY (1),PosZ (ObjectID)-PosZ (1)
   d#=Length Vector3(1)
Endfunction d#

Function Get_Object_Distance(Obj1,Obj2)
   Set Vector3 1,PosX (Obj1)-PosX (Obj2),PosY (Obj1)-PosY (Obj2),PosZ (Obj1)-PosZ (Obj2)
   d#=Length Vector3(1)
Endfunction d#

Function Get_Limb_Distance(Obj1,L1,Obj2,L2)
   Set Vector3 1,LPosX (Obj1,L1)-LPosX (Obj2,L2),LPosY (Obj1,L1)-LPosY (Obj2,L2),LPosZ (Obj1,L1)-LPosZ (Obj2,L2)
   d#=Length Vector3(1)
Endfunction d#


Function Move_Bullets()
   For i = 1000 to 1200
      If Object Exist(i)
         If Object Visible(i)
            Pitch Object Down i,.3
            For j=0 to Array Count(Roid(0))
               If Object Visible(100+j)=1
                  r#=Get_Limb_Distance(i,1,100+j,1)
                  if r#<2
                     Hide Object 100+j
                     Hide Object i
                     Exit
                  Endif
               Endif
            Next j
         Endif
      Endif
   Next i
Endfunction


Function Make_Bullet()
   b=Free_Bullet()
   if b=0 then exitfunction
   If Object Exist(b)=0
      Make Object triangle b,-.05,0,0,0,0,3,.05,0,0
      Make Mesh From Object 1,b
      Add Limb b,1,1
      Offset Limb b,1,0,199.3,0
      Color Limb b,1,rgb(255,0,0)
      Set Object Emissive b,rgb(200,100,100)
      Set Object Cull b,0
   Else
      Show Object b
   Endif
   Rotate Object b,AngX (3),AngY (3), AngZ (3)
   Pitch Object Down b,.5
Endfunction

Function Free_Bullet()
   flag=0
   For i = 1000 to 1200
      If Object Exist(i)=0
         flag=1
         Exit
      Endif
      If Object Visible(i)=0
         flag=1
         Exit
      Endif
   Next i
   i=i*flag
Endfunction i


Function Splotch(h,s)
   Lock Pixels
   Ink 0,0
   Box 200,200,230+s,230+s
   c=rnd(7)+h-3
   Ink Rgb(c,c,c),0
   r=rnd(s/2)+s/4
   For i# = 0.0 to 360.0 step 2
      x=sin(i#)*r+215+s/2
      y=cos(i#)*r+215+s/2
      line 207+s/2,207+s/2,x,y
      r=r+(rnd(2)-1)
      if r>s+15 then r=s+15
      m=s-15:If m<2 then m=2
      if rthen r=m
   Next i#
   Unlock Pixels
   Get Image 1,200,200,230+s,230+s
Endfunction



#Constant PosX Object Position X
#Constant PosY Object Position Y
#Constant PosZ Object Position Z

#Constant AngX Object Angle X
#Constant AngY Object Angle Y
#Constant AngZ Object Angle Z

#Constant CPosX Camera Position X
#Constant CPosY Camera Position Y
#Constant CPosZ Camera Position Z

#Constant CAngX Camera Angle X
#Constant CAngY Camera Angle Y
#Constant CAngZ Camera Angle Z

#Constant LPosX Limb Position X
#Constant LPosY Limb Position Y
#Constant LPosZ Limb Position Z

#Constant LDirX Limb Direction X
#Constant LDirY Limb Direction Y
#Constant LDirZ Limb Direction Z

#Constant LAngX Limb Angle X
#Constant LAngY Limb Angle Y
#Constant LAngZ Limb Angle Z
Posted: 16th Jun 2007 5:35
Start by looking here:

http://forum.thegamecreators.com/?m=forum_view&t=103103&b=1

You can expand your research by just searching "sphere".

good luck.