www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: D4NM4N on January 27, 2011, 11:53:06 pm

Title: Some object manipulation funcs needed.
Post by: D4NM4N on January 27, 2011, 11:53:06 pm
Hi,

I would be soo grateful if someone can help me out with this.


Being totally useless with maths (I have no idea how mat4 works) I want to write a small wrapper some manipulation commands for converting some code.

Basically the engine I was using was Blitz3D. (I use irrlicht a bit too, but I managed to make some funcs for that)
I have extended Object3D and wish to create the following:

Code: [Select]
PositionEntity(float x, float y, float z) //or vector
{
      //Sets the position of the object. (using world coords)
      // is setOrigin(new SimpleVextor(xyz)); what i want?
}

MoveEntity(float x, float y, float z) //or vector
{
      //moves the object in xyz from it's current position in relation to it's rotation.(using world coords)
}

TranslateEntity(float x, float y, float z) //or vector
{
      //Similar to moveentity but moves the object from its current position but using a 0,0,0 rotation.
      // does the existing translate do this?
}

TurnEntity(float x, float y, float z) //or vector
{
      //turns the object in xyz at it's current position in relation to it's current rotation. (using world coords)
      //At the moment i am using rotateX() which seems to be doing it, is this the best way?
}

RotateEntity(float x, float y, float z) //or vector
{
      //Sets the rotation of the object. (using world coords)
 
}



The other thing i cannot work out is why is the getXaxis() etc returning vectors? I was expecting to see a float. The other thing is the camera and lights seem to have setRotation and setPosition, but object3d does't :S

I think if i can get these 5 methods working i will be well on my way.
Title: Re: Some object manipulation funcs needed.
Post by: Thomas. on January 28, 2011, 02:38:43 am
You can do this in another world
Title: Re: Some object manipulation funcs needed.
Post by: Kaiidyn on January 28, 2011, 07:51:20 pm
All object3d methods work with object space coordinates,
you can change the position of an object using translate and rotation using rotateX rotateY and rotateZ,
unfortinately this does not use world-space, you could 'simulate' this using a couple fo SimpleVectors that store the data
when you do this, and call the translate or rotate commands, make sure you call clearRotation() or clearTranslation().
not sure how to explain it right now, but it might get you going.

Kind regards,
Kaiidyn.
Title: Re: Some object manipulation funcs needed.
Post by: D4NM4N on January 28, 2011, 09:39:12 pm
Hmm thats a pity, I think i might need to convert it somehow (as well as the odd twist in X axis :)) but as i said maths is not my forte.

So, by object space you are referring to the objects own scaled coordinates?
ie; for a loaded object scaled by 2x a translation of 20 will actually move 40 in world coords? If it is indeed object coord system only, then i guess i will have to load all my models in the right scale. - no biggie.

I think i have sussed out a way of positioning translating and rotating (for position i set an empty new matrix which seems to clear the translation which is kind of what i want. I assume for rotateentity i just clear the rotation and re-rotate it to the specified values?)

My biggest problem i think is "moveentity". The other big grief issue is how to get the XYZ coords of an object in relation to 0,0,0. Get center is one way, but i need the actual model's axis.
Title: Re: Some object manipulation funcs needed.
Post by: EgonOlsen on January 28, 2011, 10:42:48 pm
You should really try to understand, what these get?Axis()-methods actually do. I think it will solve some of your tasks, if i understood them correctly. Also look at getTranslation() and getTransformedCenter(). And don't do a setTranslationMatrix(new Matrix())....a call to clearTranslation() is much cheaper.
I can't be of any more help atm, because i'm feeling sick and i'm typing this on the phone....
Title: Re: Some object manipulation funcs needed.
Post by: D4NM4N on January 28, 2011, 10:56:13 pm
Thanks for the help :)

Hope you feel better
Title: Re: Some object manipulation funcs needed.
Post by: EgonOlsen on January 29, 2011, 10:45:43 am


Hope you feel better
Not really...its some swine flu infection or something..
Title: Re: Some object manipulation funcs needed.
Post by: EgonOlsen on February 01, 2011, 09:49:51 pm
Have you found out how to implement these helper methods or do you still need help?
Title: Re: Some object manipulation funcs needed.
Post by: D4NM4N on February 02, 2011, 10:56:42 pm
Kind of, I think i have got position, rotate and turn nailed (needs more testing to confirm)
i am still working on moveentity though, Basically i want it to move in relation to its rotation.
For example:
if an object is pointing 'southeast' and has a right hand 'roll' of say 30' a left movement will send it 'northeast' and upwards.. etc...

(sorry about the compass bearings, but best thing i could think of :D)

If i can get this little extention working i will post them here in case anyone else finds them useful. I will also try and do something similar for cameras and lights (using a nullentity to guide/rotate them).
If i can do this then i should be able to convert my game logic quite easily.
Title: Re: Some object manipulation funcs needed.
Post by: EgonOlsen on February 02, 2011, 11:02:15 pm
i am still working on moveentity though, Basically i want it to move in relation to its rotation. ie if it is pointing 'southeast' and rotated a bit right a left movement will send it 'northeast' and upwards.. etc...

Something like:

Code: [Select]
SimpleVector dir=obj.get?Axis(); // ?=X,Y,Z
dir.scalarMul(x);
obj.translate(dir);
???
Title: Re: Some object manipulation funcs needed.
Post by: D4NM4N on February 02, 2011, 11:56:53 pm
Great, That may have cracked it... no idea what scalarMul means but it seems to be doing something promising. :D

Code: [Select]
   public void MoveEntity(float x, float y, float z)
    {
        SimpleVector dir;
        dir=this.getXAxis(); // ?=X,Y,Z
        dir.scalarMul(x);
        this.translate(dir);
        dir=this.getYAxis(); // ?=X,Y,Z
        dir.scalarMul(y);
        this.translate(dir);
        dir=this.getZAxis(); // ?=X,Y,Z
        dir.scalarMul(z);
        this.translate(dir);
    }
I wont know for sure until i put in the time to test it properly. The whole Xaxis rotation thing is taking some getting used to  :-\.  
(Is there any way to set the engine to use standard world orientation (+y = up, +Z=away)

Here are my others most -seem- to be working ok. :)
Code: [Select]

    //PositionEntity
    public void PositionEntity(float x, float y, float z) {PositionEntity(new SimpleVector(x, y, z));}
    public void PositionEntity(SimpleVector dest)
    {
        this.setOrigin(dest);
        this.clearTranslation();
        if (_camera3D != null)
        {
            _camera3D.setPosition(dest);
        }
        if (_light != null)
        {
            _light.setPosition(dest);
        }

    }

    //RotateEntity
    public void RotateEntity(float x, float y, float z) {RotateEntity(new SimpleVector(x,y,z);}
    public void RotateEntity(SimpleVector rotation)
    {
        //conversion to degrees?
         _object3D.clearRotation();
        _object3D.setRotationPivot(rotation);
    }

    //ScaleEntity
    public void ScaleEntity(float x, float y, float z){ScaleEntity(new SimpleVector(x, y, z));}
    public void ScaleEntity(SimpleVector size)
    {
        throw new NotImplementedException();
    }

    //TranslateEntity
    public void TranslateEntity(float x, float y, float z) {TranslateEntity(new SimpleVector(x, y, z) );}
    public void TranslateEntity(SimpleVector offset )
    {
        this.translate(offset);
    }

    public void TurnEntity(SimpleVector rotation) {TurnEntity(rotation.x, rotation.y, rotation.z);}
    public void TurnEntity(float x, float y, float z)
    {
        this.rotateX(x);
        this.rotateY(y);
        this.rotateZ(z);

        if (_camera3D != null)
        {
            SimpleVector rot = this.getRotationPivot();
            _camera3D.rotateCameraX(rot.x);
            _camera3D.rotateCameraY(rot.y);
            _camera3D.rotateCameraZ(rot.z);

        }
    }