Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (777)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
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  
  How to manually rotate Bodies ?  (Read 3020 times)
0 Members and 1 Guest are viewing this topic.
Offline NewbTon

Junior Devvie




Odejava games rock!


« Posted 2005-07-01 00:40:40 »

Hi

I wonder how one would rotate one body around another body (without using forces).
I have this ragdoll that I've been working on last 6 months or so. In a game it would be very handy to be able to
rotate the ragdoll around the ragdolls center, to be able to orient it correctly when the game starts or
when you for some reason would have to "teleport" it to another location.

I know it's a math question but I have no idea how to solve this and I guess this problem would come up alot
in ODE since you can't just use a transformgroup like in most scenegraph API's
Thanks, NewbTon
Offline arne

Senior Devvie




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


« Reply #1 - Posted 2005-07-01 12:36:00 »

if you want to rotate body1 around body2 do this (b1,b2 are the Matrices that represent the positions of body1 and body2):

temp = b2.inverse();
b1.mul(temp);
b1.mul(your_rotation_matrix)
b1.mul(b2);

This is only the main idea -how you do the implementation, you'll have to think about yourself.

:: JOODE :: Xith3d :: OdeJava ::
Offline NewbTon

Junior Devvie




Odejava games rock!


« Reply #2 - Posted 2005-07-02 02:32:12 »

Thanks arne. It's rotating now but  they dont change position.  Where do I get the position and rotation into one Matrix ?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline arne

Senior Devvie




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


« Reply #3 - Posted 2005-07-02 11:22:58 »

matrix4f got functions like setRotation(Quat4f) and setTranslation(Vector3f)

:: JOODE :: Xith3d :: OdeJava ::
Offline NewbTon

Junior Devvie




Odejava games rock!


« Reply #4 - Posted 2005-07-02 16:44:12 »

I tried using Matrix4f. Still not working.Heres my code.  Any idears ?
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
  Body body1 = getBody();
    Body body2 = inBody.getBody();

    Matrix4f angle = new Matrix4f(inAngle,body1.getPosition(),1f);
    Matrix4f b1 = new Matrix4f(body1.getRotation(),body1.getPosition(),1f);
    Matrix4f b2 = new Matrix4f(body2.getRotation(),body2.getPosition(),1f);
    Matrix4f temp = new Matrix4f(b2);
    temp.invert();
    b1.mul(temp);
    b1.mul(angle);
    b1.mul(b2);

    //
    Vector3f position = new Vector3f();
    Matrix3f rotation = new Matrix3f();
    b1.get(position);
    b1.get(rotation);
    body1.setRotation(rotation);
    body1.setPosition(position);
Offline arne

Senior Devvie




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


« Reply #5 - Posted 2005-07-03 10:00:21 »

don't set a Position in angle. Angle has to be a pure rotation matrix.

:: JOODE :: Xith3d :: OdeJava ::
Offline Amos Wenger

Senior Devvie




Everything's possible, but not everything's fun...


« Reply #6 - Posted 2005-07-13 09:33:02 »

Isn't GeomTransform a sort of TransformGroup ?
I think it would be useful, but I didn't used it before, so I can't be sure.

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline arne

Senior Devvie




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


« Reply #7 - Posted 2005-07-13 10:04:20 »

GeomTransform is a Geom inside a Body which contains another Geom (e.g. a Box) When the body collides the Body changes the position and not the GeomTransform. And he wants to changes the Body, because the other way round would be to manipulate the objects itself with the effect of different centers of gravity (always (0|0|0) of the Body and NOT of the geomTransform or whatever). GeomTransforms are useful, when you want to have more complex bounding-structures (e.g. different Geoms inside a Body).

:: JOODE :: Xith3d :: OdeJava ::
Offline Amos Wenger

Senior Devvie




Everything's possible, but not everything's fun...


« Reply #8 - Posted 2005-07-14 11:40:46 »

OK.  Grin

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline NewbTon

Junior Devvie




Odejava games rock!


« Reply #9 - Posted 2005-07-18 02:51:05 »

don't set a Position in angle. Angle has to be a pure rotation matrix.
Well I have to set a position somewhere, since its rotating around a point I guess.
Are you 100 % sure this is working arne ? It's not working here but then again I dont know what im doing.
I'm really trying HARD to learn how to use matrices but damn..the tuturials advice you to learn trigonemetry first,
the trigonemetry turtorials advice you to learn geometry, the geometry tutorials. advice you to learn algebra.
I don't know , should I really spent next five years on this ?
Why aint there just some Java library that contains all the functions you will ever need Smiley


Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline arne

Senior Devvie




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


« Reply #10 - Posted 2005-08-01 08:16:58 »

You're setting the position twice - once in angle and once in b1.

Ok - I'm not 100% sure that it works - but it should.

:: JOODE :: Xith3d :: OdeJava ::
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #11 - Posted 2005-08-02 05:29:24 »

FYI, GeomTransform probably shouldn't be used for static geometry, only for positioning geometry relitive to its parent Body.  The reason I say this is that the less possible points of failture, the easier it is to debug.

You should be able to use the javax.vecmath package to convert the values around.  If you don't know how to use it, it's probably a good idea to learn.  Most 3D API's either use it, or some variation (the maths is the same).

I am 100% sure that you can manually position Bodies and Geoms.  If needed I can dig up my code.

When joints are involved, it's a little more complex, as you have to also move the attached bodies (or your simulation goes boom).  I have solved this problem though.

Cheers,

Will.

Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (288 views)
2018-11-16 13:46:03

hadezbladez (157 views)
2018-11-16 13:41:33

hadezbladez (289 views)
2018-11-16 13:35:35

hadezbladez (70 views)
2018-11-16 13:32:03

EgonOlsen (2133 views)
2018-06-10 19:43:48

EgonOlsen (2151 views)
2018-06-10 19:43:44

EgonOlsen (1363 views)
2018-06-10 19:43:20

DesertCoockie (1966 views)
2018-05-13 18:23:11

nelsongames (1599 views)
2018-04-24 18:15:36

nelsongames (2247 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!