Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Getting Velocity relative to a Body  (Read 2586 times)
0 Members and 1 Guest are viewing this topic.
Offline Browndog

Senior Newbie





« Posted 2006-05-28 03: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
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #1 - Posted 2006-05-28 04: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.

弾幕 ☆ @mahonnaiseblog
Offline Browndog

Senior Newbie





« Reply #2 - Posted 2006-05-28 06: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?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline arne

Senior Member




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


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

What about this?
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 ::
Offline otelo

Junior Member





« Reply #4 - Posted 2006-05-28 12: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? Smiley
Offline Browndog

Senior Newbie





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

Thanks arne thats exactly what I was looking for Smiley.

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 Smiley 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.
Offline otelo

Junior Member





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

Thanks arne thats exactly what I was looking for Smiley.

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 Smiley 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 );
Offline Browndog

Senior Newbie





« Reply #7 - Posted 2006-05-29 01: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 world
Vector3f  FinalForce = FinalForce.sub(relForce, myBody.getLinearVel());  // removes the current velocity from the body which stops sliding
myBody.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?
Offline otelo

Junior Member





« Reply #8 - Posted 2006-05-29 10: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
Offline Browndog

Senior Newbie





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

How do I get local velocity though thats what I'm after?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline arne

Senior Member




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


« Reply #10 - Posted 2006-05-30 14: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 ::
Offline otelo

Junior Member





« Reply #11 - Posted 2006-05-30 18: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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (37 views)
2014-07-18 06:55:21

Zero Volt (35 views)
2014-07-17 23:47:54

danieldean (28 views)
2014-07-17 23:41:23

MustardPeter (31 views)
2014-07-16 23:30:00

Cero (46 views)
2014-07-16 00:42:17

Riven (47 views)
2014-07-14 18:02:53

OpenGLShaders (36 views)
2014-07-14 16:23:47

Riven (36 views)
2014-07-14 11:51:35

quew8 (32 views)
2014-07-13 13:57:52

SHC (69 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!