www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: ErDetEnAnd? on January 19, 2009, 05:09:03 pm

Title: Good litterature on matrices is hard to find.
Post by: ErDetEnAnd? on January 19, 2009, 05:09:03 pm
Hello.

Again I'm sitting trying to figure out why the translation/rotation is acting the way it is. Does anyone have any good references.

I'm dragging an object in the scene, by turning mouse x,y coords into world x,z coords (y is constant). Its works fine (except the perspective distortion), but how to I keep translation according to the mouse when its parent is rotated?

newDraggingObject3DPosition.matMul(parent.getRotationMatrix().cloneMatrix());
Title: Re: Good litterature on matrices is hard to find.
Post by: paulscode on January 20, 2009, 08:14:29 am
I can't help you much with the first question, but if I understand your second question correctly, I think you could use camera.getUpVector() and camera.getSideVector() to determine what directions in world space to translate the child.  Then to take the parent's rotations into consideration, I recently wrote a method for doing that:

Code: [Select]
    private void translateChild( Object3D childObject, SimpleVector translation )
    {
        Object3D[] parentObjects = childObject.getParents();
        if( parentObjects == null || parentObjects.length == 0 )
        {
            childObject.translate( translation );
            return;
        }

        Object3D parentObject = parentObjects[0];
       
        Matrix m = new Matrix( parentObject.getWorldTransformation() );
        float[] dm = m.getDump();
        for( int i = 12; i < 15; i++ )
        {
            dm[i] = 0;
        }
        dm[15] = 1;
        m.setDump( dm );
       
        SimpleVector worldTranslation = new SimpleVector( translation );
        worldTranslation.matMul( m.invert3x3() );
        childObject.translate( worldTranslation );
    }

Let me know if it doesn't work, or if this isn't what you are looking for.
Title: Re: Good litterature on matrices is hard to find.
Post by: EgonOlsen on January 20, 2009, 08:50:13 am
I don't know any good reference either ATM, but i want to drop a quick note just to avoid confusion: A lot of literature from the states works with column major matrices (like OpenGL does) while most literature from europe uses row major matrices (like jPCT does). It's not common to state which one one is using at the beginning, so this can lead to great confusion... ;D
Title: Re: Good litterature on matrices is hard to find.
Post by: ErDetEnAnd? on January 20, 2009, 09:25:30 am
Thanks Paul - it works (ur way):

When turning the parent to any orientation and translating the child, the child moves up the camera z-axis when mouse is moved up (down mouse y-axis), and right on the screen when mouse moved to the right. This is almost perfect in my case. Moving the mouse on it's y-axis should result in a movement in same direction but according to its parent orientation, meaning the object would always follow the mouse while looking down the parent's y-axis, or down camera z-axis if looking at the parent from the side. Make sense?
Title: Re: Good litterature on matrices is hard to find.
Post by: ErDetEnAnd? on January 22, 2009, 05:42:06 pm
Do you have any suggestions Paul (or anyone else)?  :)
Title: Re: Good litterature on matrices is hard to find.
Post by: EgonOlsen on January 22, 2009, 09:14:24 pm
Do you have any suggestions Paul (or anyone else)?  :)
Maybe i would...if i would only understand what you are after...??? A simple drawing always helps me to understand such things better...
Title: Re: Good litterature on matrices is hard to find.
Post by: paulscode on January 22, 2009, 10:52:27 pm
Sorry, I am somewhat confused by "Moving the mouse on it's y-axis should ... always follow the mouse while looking down the parent's y-axis, or down camera z-axis if looking at the parent from the side".  It seems to me that if looking from below the parent showed movement along the camera's y-axis, then looking from the right would show movement along the camera's x-axis, not it's z-axis (perhaps you mean looking at the object from the front)?  Anyway, I am sure that I'm just not visualizing what you are talking about.  Perhaps a drawing as Egon suggests might help.
Title: Re: Good litterature on matrices is hard to find.
Post by: C3R14L.K1L4 on January 30, 2009, 01:46:53 pm
In my opinion jPCT hides a lot of matrix manipulation from you, so unless you want to use strange transformations, deformations, etc., simple translations, scaling, rotations (and possibly skews?) can be done from the self explained methods on Object3d.

If you want to learn the math behind transformations, search for "Linear Algebra" on google and books.
http://en.wikipedia.org/wiki/Linear_algebra (http://en.wikipedia.org/wiki/Linear_algebra)

For instance, for the translation
http://en.wikipedia.org/wiki/Translation_(geometry) (http://en.wikipedia.org/wiki/Translation_(geometry))

Books? Ok, here they go:
Linear Algebra And Its Applications
3D Game Engine Design
3D Math Primer for Graphics and Game Development
A Mathematical Introduction With OpenGL
Tricks of the 3D Game Programming Gurus - Advanced 3D Graphics and Rasterization