Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (754) Games in Android Showcase (229) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Getting Velocity relative to a Body  (Read 4834 times) 0 Members and 1 Guest are viewing this topic.
Browndog

Senior Newbie

 « Posted 2006-05-28 01:02:44 »

Hi,

Can somone tell my how to get velocity relative to my ship? That is the velocity as if my ship were at (0,0,0).

Thanks
oNyx

JGO Coder

Medals: 2

pixels! :x

 « Reply #1 - Posted 2006-05-28 02:03:29 »

Say you move at 50 units per second along the x-axis... chasing another entity running along the x-axis with a speed of 48ups. Then the relative (to you) speed (along the x-axis) of that entity is -2 ups. If it were moving at 60ups the relative speed would be 10ups.

Thats all there is to it.

Browndog

Senior Newbie

 « Reply #2 - Posted 2006-05-28 04:01:53 »

No thats not reall what I am talking about. I'll explane. My body has a velocity of (x, y ,z) where x, y, z are the change in position relative to the origin(0,0,0), what I want is my body's velocity relative to itself not the origin. So to give you an example say my body is facing down the X axis and is traveling at 1 unit per second my velocity will be (0,0,1) now lets say I turn my ship 180 degress so its going straight down the X axis in the other direction my velocity is now (0,0,-1)  that is relative to the origin. The velocity in both cases relative to my body is (0,0,1) because I am moving forwards in both cases. So does anyone know a calculation that can convert a velocity so its relative to my body no the origin?
arne

Senior Devvie

money is the worst drug- we should not let it rule

 « Reply #3 - Posted 2006-05-28 08:36:59 »

 1  2  3  4 `Vector3f velocity; //the velocity of your ship in world coordinates (rotation)Matrix3f rotation; //the orientation of your ship rotation.invert();shipVel = rotation.mul(velocity); //shipVel is the velocity of your ship relative to the direction the ship is pointing at`

:: JOODE :: Xith3d :: OdeJava ::
otelo

Junior Devvie

 « Reply #4 - Posted 2006-05-28 10:19:20 »

No thats not reall what I am talking about. I'll explane. My body has a velocity of (x, y ,z) where x, y, z are the change in position relative to the origin(0,0,0), what I want is my body's velocity relative to itself not the origin. So to give you an example say my body is facing down the X axis and is traveling at 1 unit per second my velocity will be (0,0,1) now lets say I turn my ship 180 degress so its going straight down the X axis in the other direction my velocity is now (0,0,-1)  that is relative to the origin. The velocity in both cases relative to my body is (0,0,1) because I am moving forwards in both cases. So does anyone know a calculation that can convert a velocity so its relative to my body no the origin?
You make little sense to me. Just save your ships position from one step back, then compare to its current position, using your time step you can calculate the speed or what ever you want with it. Relative speed to itself... are you going all 'theory of relativity' on us?
Browndog

Senior Newbie

 « Reply #5 - Posted 2006-05-28 12:32:12 »

Thanks arne thats exactly what I was looking for .

The problem I have is I'm not used to the way javax.vecmath does rotation. I'm my program I mainly deal with 4x4 matrix and euler values. I'm sure I get used to it as I use it more.

Quote
Relative speed to itself... are you going all 'theory of relativity' on us?
lol no I just want to know my speed, I think if the speedo in a car read your speed relative to the origin rather than relative to your car you would have problems.
otelo

Junior Devvie

 « Reply #6 - Posted 2006-05-28 13:36:34 »

Thanks arne thats exactly what I was looking for .

The problem I have is I'm not used to the way javax.vecmath does rotation. I'm my program I mainly deal with 4x4 matrix and euler values. I'm sure I get used to it as I use it more.

Quote
Relative speed to itself... are you going all 'theory of relativity' on us?
lol no I just want to know my speed, I think if the speedo in a car read your speed relative to the origin rather than relative to your car you would have problems.
aaah, I think I get it.

but in a car I would expect the world coordinate speed vektor to be aligned with my car's orientation (momentarily), if not, then I'm sliding a lot and my forward speed would be the least of my worries.

my suggestion would be:

Vector3f worldVelocity;
Vector3f carForward; // - normalized!
Transform3D carTransform;
float forwardVelocity;

carTransform.transform( carForward );
forwardVelocity = worldVelocity.dot( carForward );
Browndog

Senior Newbie

 « Reply #7 - Posted 2006-05-28 23:24:27 »

arne I have one question about your code example. rotation.mul(velocity) does not seem to work mul does not accept a Vector3f, it looks like it only takes another Matrix3f, do you think you could help me fix this please?

Quote
but in a car I would expect the world coordinate speed vektor to be aligned with my car's orientation (momentarily), if not, then I'm sliding a lot and my forward speed would be the least of my worries.

Yeah that sliding is exactly what I am trying to counter act. I dont think setting a velocity will work to well as it will counter collisions so I will go straight through things I shouldn't. I am applying a force to my body not a velocity.

Currently I do this:

 1  2  3 `Vector3f relForce = getRelForce(speedForce); //get the force to apply to the body relative to the worldVector3f  FinalForce = FinalForce.sub(relForce, myBody.getLinearVel());  // removes the current velocity from the body which stops slidingmyBody.addForce(finalForce); //apply forces to body`

This works fairly well as long as the body is moving forwards however if my body hits and object and bounces backwards my linera velocity is negative and FinalForce.sub(relForce, myBody.getLinearVel()); add the 2 forces together which creates a situation where I now have more force than I'm supposed to. I think I can fix this using the example arne provided.

But otelo I have seen other examples around of what you describe and it sounds interesting. My question is from your code what is carForward and what does carTransfrom do and do your think it would apply the same way to force not velocity?
otelo

Junior Devvie

 « Reply #8 - Posted 2006-05-29 08:08:12 »

Vector3f worldVelocity; //your global velocity vector
Vector3f carForward; // - normalized! your car's local forward vector e.g.  (0,0,1)
Transform3D carTransform; // your car's current world transform
float forwardVelocity; // your relative velocity
Browndog

Senior Newbie

 « Reply #9 - Posted 2006-05-30 04:05:40 »

How do I get local velocity though thats what I'm after?
arne

Senior Devvie

money is the worst drug- we should not let it rule

 « Reply #10 - Posted 2006-05-30 12:19:26 »

ohh yeah Matrix3f(4f).mul only multiplies Matrices...I believe it's called transform, if you want to multiply Vectors with matrix.

:: JOODE :: Xith3d :: OdeJava ::
otelo

Junior Devvie

 « Reply #11 - Posted 2006-05-30 16:33:21 »

How do I get local velocity though thats what I'm after?
I had it wrong ... I was going for all 3 velocity components, but it wasn't right anyway. I made some corrections to the posts above. take a look.
Pages: [1]
 ignore  |  Print

 DesertCoockie (22 views) 2018-05-13 18:23:11 nelsongames (72 views) 2018-04-24 18:15:36 nelsongames (67 views) 2018-04-24 18:14:32 ivj94 (751 views) 2018-03-24 14:47:39 ivj94 (81 views) 2018-03-24 14:46:31 ivj94 (605 views) 2018-03-24 14:43:53 Solater (97 views) 2018-03-17 05:04:08 nelsongames (170 views) 2018-03-05 17:56:34 Gornova (388 views) 2018-03-02 22:15:33 buddyBro (1048 views) 2018-02-28 16:59:18
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org