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.

Dark GDK / Having trouble with Newtonian flight.

Author
Message
Stucky
15
Years of Service
User Offline
Joined: 11th Apr 2009
Location:
Posted: 22nd Jul 2009 11:54
I'm making space sim, right now its only a proof of concept but at the moment it seems to be far from proven. I want the spaceship to fly like a real space ship. When you accelerate in one direction, with zero friction present, you have to accelerate an equal amount in the opposite direction if you want to come to a stop.

Because the spaceship will not always be facing perfectly down the X, Y, or Z axises I have to use trigonometry to figure out the resultant velocities. This is where I run into trouble. I've already searched the forums and found equations to find the resultant velocity on each axis. I even tested them out and they work out just fine at the start of the game. But then after flying around for more than a few seconds everything goes wrong, moving forward causes you to move up, moving to the left makes you move forward, ect. Here's the code I'm using if it helps. I won't post the whole program cause I'm pretty sure this is all that needs to be seen for this particular problem.



Thanks for your time.
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 22nd Jul 2009 14:32
Instead of *ToRad you should use dbSin etc, to keep it univeral (dbSin uses degrees).
A quick skim over and I could not see any problems. It might be good to see your input code.

randal
15
Years of Service
User Offline
Joined: 18th Nov 2008
Location:
Posted: 22nd Jul 2009 16:12
would your spaceship not 'fly' better if you move forward/backward with dbMove() and use dbTurn() & dbPitch() for direction?
Phosphoer
16
Years of Service
User Offline
Joined: 8th Dec 2007
Location: Seattle
Posted: 22nd Jul 2009 20:18 Edited at: 29th Jul 2009 23:33
@Randal: dbMove( ) would not allow for newtonian flight, which requires that you continue moving in the direction you started, regardless of which direction you are currently facing. Besides, always better to avoid the 'black box' commands when possible :p

I cannot see any problems with your code either. The only thing I could imagine is that perhaps your velocities were not initialized properly? Show us more codez ^^

Stucky
15
Years of Service
User Offline
Joined: 11th Apr 2009
Location:
Posted: 23rd Jul 2009 06:54
K, I guess I'll post the entire code then. I'll do my best to clean it up a bit and add comments for easy reading. I will also attach an ESC file so you can see exactly what's going on with the program.
Controls:
W = forward throttle
A & D = Strafe keys, not usable yet
S = backward throttle
Space bar = Hold down to bring the ship to a complete stop

Attachments

Login to view attachments
randal
15
Years of Service
User Offline
Joined: 18th Nov 2008
Location:
Posted: 23rd Jul 2009 11:47
oh ok, i see what you mean.
mikeMarek 597
15
Years of Service
User Offline
Joined: 12th Feb 2009
Location:
Posted: 23rd Jul 2009 20:39
I've noticed that dbSin(), dbCos)(, and dbTan() don't work very well when I have used them. I include the <cmath> file, and use sin(), cos(), and tan() functions from there. Also, I use this code to move objects around:


It shouldn't be too hard to incorperate the z-axis into there...

Wait... What were we talking about?
Stucky
15
Years of Service
User Offline
Joined: 11th Apr 2009
Location:
Posted: 29th Jul 2009 10:05 Edited at: 29th Jul 2009 10:06
Sorry I haven't replied in a while, been busy. Now back to the topic of the thread. I haven't seen much improvement whether I'm using the cmath trig functions or the Dark GDK trig functions. The ship still moves in unusual ways.

Can someone confirm that I have the formulas for each axis correct? I searched all over the internet and those were the best I could come up with.

Please feel free to download the .exe file attached to this reply so you can better understand what's going with the program during runtime.

Attachments

Login to view attachments
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 29th Jul 2009 18:17 Edited at: 29th Jul 2009 19:04
I hate to say these two words but I'm afraid you may be experiencing "Gimble Lock", I spent weeks on something similar to this using directX and I never figured it out, in fact thats why I came back to DarkGDK.

Like I said, I never figured it out so I dont have all the answers, I see you are using functions like dbTurnLeft(), dbPitchObjectUp() etc.. which gives you free motion, but your math equations may not be compatable with this kind of motion.
The Turn, Pitch commands probably use advanced maths(quaternions) for this kind of motion where your equations dont, therefore your equations are likely to cause Gimble Lock(I hope I'm wrong).

To simplify things you could use your math equations to control the ship(cube) instead of the dbTurn etc.. and get rid of velocity for now, that way you can see first hand exactly what your equations are doing, I have a bad feeling that they will not work for free motion. To put it another way, use the equations to change the ships position and not its velocity as it will be easier to see whats happening, you might want to put a few more planets in as visual aids as it may get confusing.

I may be completely wrong, I will think about it a bit more and get back to you if I come up with a solution.

Good luck.

Edit: Just noticed that your ship does not roll, this would make me think that basic trig functions should be fine without the risk of Gimble lock, perhaps its the fact you are using dbTurn() etc.. instead of dbRotateObject(), I'm just thinking out loud, sorry if I'm making things more confusing than they already are.
Stucky
15
Years of Service
User Offline
Joined: 11th Apr 2009
Location:
Posted: 29th Jul 2009 21:04
Well I looked up gimbal lock on wikipedia and I still don't see how it could happen. The example it gives you on the wikipedia page (the one with the two pictures) shows a plane with gimbals around it that rotate around their respective axises. Then the second picture shows that the plane has been pitched up by 90 degrees, and that the green and blue gimbals have some how fused together. I just don't see how this could happen though? Depending on whether you're looking at the angles as being local or global, wouldn't the blue gimbal rotate 90 degrees around the red gimbal just as the green one has? I don't see why one gimbal would rotate to changes in the red gimbal but another one would not.

Well if you help me to understand gimbal lock better that'd be cool. I'm not saying that it isn't what's causing my problems I just want to have an understanding of it.

I found a tutorial on how to use quaternions for 3D rotation. So I'm probably going to give it a try. It looks like everyone uses quaternions now days instead of trigonometry.
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 29th Jul 2009 23:52
I wish I understood gimble lock properly but I dont, what I'm pretty sure about is that free form rotation about all three axis can't be done with basic trig functions.

It sounds like you are pretty determined to get your newtonian flight, you could learn to do quaternions but surly it is not needed with the GDK. I'm pretty sure there will be a relatively straight forward way of doing it with the functions available with GDK.

Ive been messing with your code and have not really got far yet, I did change it so your equations control the ships position and it did make it alot clearer what was happening. This is a subject I have invested alot of time in and not really got far so I'm going to give it another go.

If you check out the WIP section there are a couple of space flight sims, you could always ask them if they use newtonian flight.

Let me know if you get anywhere.
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 30th Jul 2009 00:30 Edited at: 30th Jul 2009 01:13


Thats what I have so far, that was the easy part. Now to get newtonian motion without using commands that are not compatable with free form motion(dbRotate, dbPosition etc..).

If you notice the Z angle changes with these commands even though the object never rolls, I think there is black magic going on behind the scenes(quaternions perhaps).

Here are a couple of interesting commands:

dbSetObjectRotationXYZ()
dbSetObjectRotationZYX()

These could be the key to getting your trig equations to work alongside free form rotation.

Someone said above its better to avoid "black box" commands when possible, but these commands are doing all the hard work for us, otherwise we may as well go and program in DirectX.
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 30th Jul 2009 14:03
Instead of quarternions, which have no support in GDK AFAIK, use matrices - which are not affected by gimbal lock.

Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 30th Jul 2009 16:16


This code gives you Free motion Newtonian flight.

The key is to use dbMove() to give you the velocity vector, this command probably does alot of clever mathematics behind the scenes so I have found a way to use this to change velocity and not position, saving you the hassle of learning advanced 3D physics lol, although I would like to learn all that stuff someday anyway.

A nice little test is to get some sideways momentum going and then constantly accelarate toward the planet, this puts you in orbit of the planet, pretty cool.
Stucky
15
Years of Service
User Offline
Joined: 11th Apr 2009
Location:
Posted: 31st Jul 2009 01:42 Edited at: 31st Jul 2009 01:58
Awesome! I can't thank you enough Matty. I'll be sure look over your code very closely. I want to make sure I fully understand it before I use it in my program. I mean, what kind of programmer would I be if I couldn't even explain my own program?

Anyways, thanks a bunch for the help!

EDIT: I think I'll start using vectors too. I shied away from them at the start, but now I understand how to use them. It should clean things up a lot too.
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 31st Jul 2009 02:47
No problem, good luck with your game.

Login to post a reply

Server time is: 2024-10-01 08:44:46
Your offset time is: 2024-10-01 08:44:46