Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Going Insane

Author
Message
MattIsFun
21
Years of Service
User Offline
Joined: 4th Jan 2003
Location:
Posted: 9th Jan 2003 23:33
For the past week, I have been trying to understand the 3D system of DBasic. I am trying to create a simple ship moving in 3D space as a start. (I have plenty of 2D experience; I have already made pong, etc.) I've tried using trigonometry and angles, but somehow I always mess it up. I can't get the ship to move right. I know there has to be a tutorial or something out there on this subject, but I haven't been able to find one. Please, if you could give me some help on this subject, it would be appreciated.
MattIsFun
21
Years of Service
User Offline
Joined: 4th Jan 2003
Location:
Posted: 9th Jan 2003 23:39
Oh, by the way, I was going to post the code, but it's really a mess since I've been experimenting with it. It's just your generic Move Object around on X-Z plane using TURN commands.

The Darthster
22
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 10th Jan 2003 01:02
Here's some spaceflight code I wrote which might help you somewhat, if you can understand it. Some of the controls are remmed out, so there are different control options in there.



Theta is the xz angle and phi is the yz angle. You'll see how they change by running the program. The physics is for a point in space, I put the camera at that point, but you could put a spaceship model there and use a different camera system.
MattIsFun
21
Years of Service
User Offline
Joined: 4th Jan 2003
Location:
Posted: 10th Jan 2003 01:56
Thanks. Just what I was looking for.

MattIsFun
21
Years of Service
User Offline
Joined: 4th Jan 2003
Location:
Posted: 11th Jan 2003 01:30
I made a simplified engine using the basic trig equations you used. I actually understand them pretty well, now that I see what they are. Do you mind if I use this in a game?

rem initialisation
make matrix 1, 20000,20000,50,50
randomize matrix 1,200
update matrix 1

rem theta
xz# = 0
rem phi
yz# = 0

rem setup location
x# = 0
y# = 0
z# = 0

rem set speeds and forces
xvelocity# = 0
yvelocity# = 0
zvelocity# = 0
thrust# = 0
thruststep# = .1
thrustdecaystep# = .9
velodecaystep# = .99

rem misc. init
sync on
hide mouse

rem main loop
rem input
do
if upkey() = 1 then inc yz#
if downkey() = 1 then dec yz#
if leftkey() = 1 then dec xz#
if rightkey() = 1 then inc xz#
if returnkey() = 1 then thrust# = thrust# + thruststep#

rem physics
rem wrap angle values
xz# = wrapvalue(xz#)
yz# = wrapvalue(yz#)

rem change velocities according to angles
xvelocity# = xvelocity# + sin(xz#) * cos(yz#) * thrust#
yvelocity# = yvelocity# - sin(yz#) * thrust#
zvelocity# = zvelocity# + cos(xz#) * cos(yz#) * thrust#

rem add forces
xvelocity# = xvelocity# * velodecaystep#
yvelocity# = yvelocity# * velodecaystep#
zvelocity# = zvelocity# * velodecaystep#
thrust# = thrust# * thrustdecaystep#

rem add velocity to positions
x# = x# + xvelocity#
y# = y# + yvelocity#
z# = z# + zvelocity#

rem set up camera
position camera x#,y#,z#
yrotate camera xz#
xrotate camera yz#

rem display variables
text 0,0,"XZ (Theta)"
text 100,0,str$(xz#)
text 0,20,"YZ (Phi)"
text 100,20,str$(yz#)
text 0,40,"Thrust"
text 100,40,str$(thrust#)
text 0,60, "X velocity"
text 100,60, str$(xvelocity#)
text 0,80, "Y velocity"
text 100,80, str$(yvelocity#)
text 0,100, "Z velocity"
text 100,100, str$(zvelocity#)

sync
loop

MattIsFun
21
Years of Service
User Offline
Joined: 4th Jan 2003
Location:
Posted: 11th Jan 2003 01:31
The code snippet button gives me an error for some reason, so I post it directly

The Darthster
22
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 11th Jan 2003 22:13
Yeah, go ahead. I wrote that code ages ago, intended for public use. Some credit would be nice however

Login to post a reply

Server time is: 2024-11-23 21:58:37
Your offset time is: 2024-11-23 21:58:37