www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: AGP on March 27, 2014, 03:40:47 am

Title: How do I do Object3D.rotate(SimpleVector)
Post by: AGP on March 27, 2014, 03:40:47 am
Surely, the equivalent (I'm porting code from the old irrlicht engine) isn't:
Code: [Select]
someObject3D.rotateX(sv.x);
someObject3D.rotateY(sv.y);
someObject3D.rotateZ(sv.z);

Is it?
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: EgonOlsen on March 27, 2014, 07:14:26 am
No idea. For that, i would have to know what the irrlicht method does.... ???
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: AGP on March 27, 2014, 07:25:52 am
It goes like the following (whatever the equivalent irrlicht objects were):

Code: [Select]
nativeRotation.set(mesh.getRotation().x, mesh.getRotation().y + rotationY, mesh.getRotation().z);//nativeRotation WAS A vector3df (just a SimpleVector)
node.setRotation(nativeRotation);//NODE WAS SORT OF Object3D

The setRotation documentation:
http://irrlicht.sourceforge.net/docu/classirr_1_1scene_1_1_i_scene_node.html#adb6ff54f52d3a9e1514cd487a550935c (http://irrlicht.sourceforge.net/docu/classirr_1_1scene_1_1_i_scene_node.html#adb6ff54f52d3a9e1514cd487a550935c)
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: EgonOlsen on March 27, 2014, 07:39:39 am
Judging from the sparse documentation, i would think that your port is correct (maybe with different signs depending on the coordinate system), but looking at the code, i totally don't get the +yrotation part. Are you sure that this code comes from the method that takes a vector3?
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: AGP on March 27, 2014, 07:47:13 am
Yes. Why?

From what I gather, irrlicht's orientation is jpct's rotated PI around Y...
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: EgonOlsen on March 27, 2014, 08:21:11 am
Yes. Why?
Because i don't get it. Either add some stuff to all components or to none, but adding something to y only seems to make no sense when looking at it from the outside.
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: AGP on March 27, 2014, 08:27:59 am
What do you mean? The way I see it, this code is producing a SimpleVector that holds an object's current rotation on all axis (and the object is currently only being rotated around y).

What do I do if I'm right about irrlicht's orientation? Is it still someObject3D.rotateX(sv.x), someObject3D.rotateY(sv.y), someObject3D.rotateZ(sv.z)?
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: EgonOlsen on March 27, 2014, 08:53:12 am
What do you mean?
I mean this: nativeRotation.set(mesh.getRotation().x, mesh.getRotation().y + rotationY, mesh.getRotation().z);

Apart from that, i really can't tell. In theory, your idea looks fine. It depends on how Irrlicht applies the rotations (i.e. in which order). I suggest to just try it and see what happens.
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: AGP on March 27, 2014, 08:58:26 am
I know that's that to which you were referring; that's what I wrote about.

I'll go with my code for now, but I can't test it for a while: I'm working down from 1500 compilation errors across dozens of classes. I'm currently just under 1000 errors!
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: AGP on March 27, 2014, 06:44:27 pm
Too often do I need to get a Texture's name with only the texture instance in this port. Could I either get a Texture.getName() or a TextureManager.getNameByInstance(Texture)? I realize that I could use getNameByID(Texture.getExternalID()), but in my experience getExternalID() isn't always filled.
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: AGP on March 27, 2014, 10:42:29 pm
Is that a "no" or is it your day job again? :- )
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: EgonOlsen on March 28, 2014, 07:18:35 am
No, it's rather some strange concept called "sleep". Texture.getName() isn't possible, because a texture instance has no name. getExternalID() is something completely different and not suitable for this. TextureManager.getNameByInstance(Texture) sounds reasonable. I'll add it this evening.
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: AGP on March 28, 2014, 07:40:49 am
It's very strange indeed. But I did post this during what must be your afternoon... Thanks very much, pal. Have you had a chance to read my e-mail?
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: EgonOlsen on March 28, 2014, 09:15:10 pm
Please try this jar: http://jpct.de/download/beta/jpct.jar (http://jpct.de/download/beta/jpct.jar)
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: AGP on March 28, 2014, 11:23:37 pm
I had to decompile to find out the name of the method. :- )

Thanks a lot.
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: EgonOlsen on March 29, 2014, 12:14:56 am
I had to decompile to find out the name of the method. :- )
Why not start using a decent IDE (Eclipse, Netbeans...) instead... ???
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: AGP on March 29, 2014, 02:57:50 am
I only use eclipse when I absolutely have to. My proprietary notepad is FAR better and never causes any problems, unlike eclipse which gets confused way too often.
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: AGP on March 29, 2014, 07:22:12 pm
What do you suppose is Irrlicht's emissive color? Object3D.setAdditionalLight? http://irrlicht.sourceforge.net/docu/classirr_1_1video_1_1_s_material.html#a005f9acf8855681c21b3e3e7de67306f (http://irrlicht.sourceforge.net/docu/classirr_1_1video_1_1_s_material.html#a005f9acf8855681c21b3e3e7de67306f)
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: AGP on March 29, 2014, 07:44:46 pm
Also, how do I convert between vecmath's Vector3f to SimpleVector?
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: EgonOlsen on March 30, 2014, 01:31:23 pm
What do you suppose is Irrlicht's emissive color? Object3D.setAdditionalLight? http://irrlicht.sourceforge.net/docu/classirr_1_1video_1_1_s_material.html#a005f9acf8855681c21b3e3e7de67306f (http://irrlicht.sourceforge.net/docu/classirr_1_1video_1_1_s_material.html#a005f9acf8855681c21b3e3e7de67306f)
Maybe. I would take treat it as such until it turns out that it's not.
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: EgonOlsen on March 30, 2014, 01:32:38 pm
Also, how do I convert between vecmath's Vector3f to SimpleVector?
They should basically be the same thing. You might have to convert between the coordinate systems by negating some components.
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: AGP on March 30, 2014, 08:07:17 pm
Which ones should I negate? I'm not asking because I'm lazy, I'm asking because I really don't know...
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: EgonOlsen on March 30, 2014, 08:59:00 pm
I don't know either. It depends on coordinate system that irrlicht uses. Just draw that one and the one that jPCT uses, draw three point in the irrlicht one (1,0,0), (0,1,0) and (0,0,1) and see which sign points on the same positions in the jPCT coordinate system would have. Those where the sign differs are the ones that you have to negate.
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: AGP on March 31, 2014, 04:42:08 am
Irlicht has a getRotation() for its objects which returns a vector. Is that possible either on SimpleVector or on Matrix? I noticed there's a get_Axis(). If I rotated by the result of these three methods, would the result be that it clears the rotation matrix, then sets the rotation to a vector that would be the result of getRotation()?

Would this probably be the same thing?

Code: [Select]
nativeRot = ball.getRotationMatrix().getXAxis();
nativeRot.add(ball.getRotationMatrix().getYAxis());
nativeRot.add(ball.getRotationMatrix().getZAxis());
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: EgonOlsen on March 31, 2014, 08:54:20 am
No, it's more likely something like this:

Code: [Select]
public static SimpleVector deriveAngles(Matrix mat) {
SimpleVector s = new SimpleVector();
float[] m = mat.getDump();
s.x = (float) Math.atan(m[9] / m[10]);
s.y = (float) Math.asin(-m[2]);
s.z = (float) Math.atan(m[4] / m[0]);
return s;
}
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: AGP on April 01, 2014, 02:51:44 am
Thank you very much, buddy. The other end of this question is that I need to actually build a new Matrix. The following is the original code. The first block calls the second block.

Code: [Select]
float rotAngle = distance / radius * 0.5f; //rotSpeed;
Vector3f v = new Vector3f(vel.z, 0, -vel.x);
MathTools.normalize(v);
MathTools.buildRotationMatrix(rotAngle, v, matrix)l

Code: [Select]
  public static void buildRotationMatrix(float phi, Vector3f axis, matrix4 mRet)  {

    float u = axis.x;
    float v = axis.y;
    float w = axis.z;

    float rcos = (float) Math.cos(phi);
    float rsin = (float) Math.sin(phi);

    float m[] = new float[16];

    //(*this)(0,0) =      rcos + u*u*(1-rcos);
    //mRet.setM(0, rcos + u*u*(1-rcos));
    m[0] = rcos + u*u*(1-rcos);
    //(*this)(1,0) =  w * rsin + v*u*(1-rcos);
    //mRet.setM(1, w * rsin + v*u*(1-rcos));
    m[1] = w * rsin + v*u*(1-rcos);
    //(*this)(2,0) = -v * rsin + w*u*(1-rcos);
    //mRet.setM(2, -v * rsin + w*u*(1-rcos));
    m[2] = -v * rsin + w*u*(1-rcos);
    //(*this)(3,0) = 0;
    //mRet.setM(3, 0);
    m[3] = 0;

    //(*this)(0,1) = -w * rsin + u*v*(1-rcos);
    //mRet.setM(4, -w * rsin + u*v*(1-rcos));
    m[4] = -w * rsin + u*v*(1-rcos);
    //(*this)(1,1) =      rcos + v*v*(1-rcos);
    //mRet.setM(5, rcos + v*v*(1-rcos));
    m[5] = rcos + v*v*(1-rcos);
    //(*this)(2,1) =  u * rsin + w*v*(1-rcos);
    //mRet.setM(6, u * rsin + w*v*(1-rcos));
    m[6] = u * rsin + w*v*(1-rcos);
    //(*this)(3,1) = 0;
    //mRet.setM(7, 0);
    m[7] = 0;

    //(*this)(0,2) =  v * rsin + u*w*(1-rcos);
    //mRet.setM(8, v * rsin + u*w*(1-rcos));
    m[8] = v * rsin + u*w*(1-rcos);
    //(*this)(1,2) = -u * rsin + v*w*(1-rcos);
    //mRet.setM(9, -u * rsin + v*w*(1-rcos));
    m[9] = -u * rsin + v*w*(1-rcos);
    //(*this)(2,2) =      rcos + w*w*(1-rcos);
    //mRet.setM(10, rcos + w*w*(1-rcos));
    m[10] = rcos + w*w*(1-rcos);
    //(*this)(3,2) = 0;
    //mRet.setM(11, 0);
    m[11] = 0;

    //(*this)(0,3) = 0;
    //mRet.setM(12, 0);
    m[12] = 0;
    //(*this)(1,3) = 0;
    //mRet.setM(13, 0);
    m[13] = 0;
    //(*this)(2,3) = 0;
    //mRet.setM(14, 0);
    m[14] = 0;
    //(*this)(3,3) = 1;
    //mRet.setM(15, 1);
    m[15] = 1;

    mRet.setM(m);

  }
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: EgonOlsen on April 01, 2014, 07:29:35 am
Well...then just do that. You can either set each element directly in the matrix or fill a float[16]-array and set that. As usual, you have to make sure that the formats match. Matrices in jPCT are row major, i don't know about Irrlicht.
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: AGP on April 01, 2014, 08:43:45 am
Irrlicht's documentation says "4x4 matrix. Mostly used as transformation matrix for 3d calculations. The matrix is a D3D style matrix, row major with translations in the 4th row." I suppose that means that they're the same as jpct's, right, and that my work is done?
Title: Re: How do I do Object3D.rotate(SimpleVector)
Post by: EgonOlsen on April 01, 2014, 08:44:53 am
Most likely....