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.

DarkBASIC Professional Discussion / Inertial movement using vectors

Author
Message
Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 28th Oct 2003 10:54
Hello.

I found this code by an anonymous coder in the codebase:



I have four questions about it.

1) Can anybody tell me how to add a gravity vector into it?

2) How would I put the vectors into arrays so that they can address multiple players within the loop?

3) Does anybody know who the 'anonymous coder' is?

4) Can I use this code in my own project?

Thank you
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Oct 2003 15:17
If it's in the codebase you can use it.

If it's anonymous, there's a good chance it's Rich, or added by Rich when Codebase was first created.

DB Pro has it's own vector commands, you might not need to make your own Types.

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 28th Oct 2003 16:24
I'm using DBPro but i don't understand the vector commands - any tips.

Please
Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 28th Oct 2003 16:48
OK - I've been looking at vector commands in DBPro. The commands Vector2/3/4 are defined as 2/3/4 float vectors. Does that mean 2/3 or 4 decimal places in a float or am I missing something?
Beta 1
22
Years of Service
User Offline
Joined: 27th Aug 2003
Location:
Posted: 28th Oct 2003 19:08
Nope I think its the number of dimensions to the vector - but I could be wrong.

I've been implementing that sort of thing with UDTs cos I refuse to learn how to use the new commands

Without wishing to rehash the example directly.

Each of my objects properties is stored in a UDT which has a few sub-types so:

defines a threeD vector/position/whatever

TYPE ThreeD
x AS FLOAT
y AS FLOAT
z AS FLOAT
ENDTYPE

TYPE Object_t
pos AS ThreeD <- stores the 3d position in gamespace
vel AS ThreeD <- stores the current velocity in each axis (essentially a threeD vector)
ENDTYPE

Each turn through the game loop I calculate a vector representing all the forces acting on the object. Gravity would in thise case be represented by a vector pointing straight down with a fixed size.

So if these are stored in a variable acc which is a ThreeD type variable (acc for acceleration) then to add the forces acting on the ship to its current movement to give its new movement vector I do this:

So (assuming youve DIMed a Object(N) array at some point)

acc.x= (Insert sum of all forces here)
acc.y= (Insert sum of all forces here)-G <- gravity acting downwards
acc.z= (Insert sum of all forces here)

Then add this vector to the velocity vector

INC object(N).vel.x, acc.x
INC object(N).vel.y, acc.y
INC object(N).vel.z, acc.z

Then add the velocity to the position

INC object(N).pos.x, object(N).vel.x
INC object(N).pos.y, object(N).vel.y
INC object(N).pos.z, object(N).vel.z

And then update the objects position

POSITION OBJECT N, object(N).pos.x,object(N).pos.y,object(N).pos.z

Et viola vector addition and the worlds simplest physics engine.

Theres probably a much much simpler way to do this but I like this way
Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 28th Oct 2003 19:20
Thanks beta 1

I've read your code and it looks like just what I need. I will give it a try now and let you know how I get on.

Thanks
Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 28th Oct 2003 19:48
Well I thought I understood it when I read it but when it came to implimenting it into my own code I went blank.

I really appreciate the help you have offered above but could I be really cheeky and ask if you (or anyone else) could put it into a 'code snippet' form so that I can try to work out whats happening and when?

If it helps any I am only using 2D but still using 3D objects. I do however need the code to act on four ships in each loop.

Thanks again for the help above and thanks to anyone for any future help.
Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 28th Oct 2003 19:56 Edited at: 28th Oct 2003 19:57
I have put the relevent part of my code below incase it helps.

Thank you

[Edit] Ignore the first line of code. That was me trying out beta1's code but I forgot to delete that line when I failed to get it working. [\Edit]

Login to post a reply

Server time is: 2026-07-26 16:03:37
Your offset time is: 2026-07-26 16:03:37