Rotate camera in 3d around an object (using a spherical 3d coord system) by Philip27th Jan 2004 8:20
|
---|
Summary This code does exactly what it says on the tin. Description There is a slight bug when x: 0 y: 400 z: 0. You will see the camera reset. Ditto at x: 0 y: -400 z: 0. This appears to be a bug in the Point Camera command which causes the camera angles to reset. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com sync on sync rate 60 make object cube 1, 100 position object 1, 0, 0, 0 color object 1, rgb(200, 200, 200) set object light 1, 1 set object ambient 1, 0 x# = 0 y# = 0 z# = -400 position camera x#, y#, z# point camera 0, 0, 0, 0 bearing# = 0 azimuth# = 0 distance# = 400 do if leftkey() = 1 bearing# = wrapvalue(bearing# + 1) endif if rightkey() = 1 bearing# = wrapvalue(bearing# - 1) endif if upkey() = 1 azimuth# = wrapvalue(azimuth# + 1) endif if downkey() = 1 azimuth# = wrapvalue(azimuth# - 1) endif x# = distance# * sin(azimuth#) * cos(bearing#) z# = distance# * sin(azimuth#) * sin(bearing#) y# = distance# * cos(azimuth#) position camera x#, y#, z# point camera 0, 0, 0, 0 set cursor 0, 0 print "x: ";x#;" y: ";y#;" z: ";z# print "bearing: ";bearing# print "azimuth: ";azimuth# print "distance: ";distance# center text object screen x(1), object screen y(1), "Object" sync loop |