Author Topic: How do I do Object3D.rotate(SimpleVector)  (Read 2285 times)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11746
    • View Profile
    • http://www.jpct.net
Re: How do I do Object3D.rotate(SimpleVector)
« Reply #15 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... ???

Offline AGP

  • quad
  • ******
  • Posts: 1516
    • View Profile
Re: How do I do Object3D.rotate(SimpleVector)
« Reply #16 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.

Offline AGP

  • quad
  • ******
  • Posts: 1516
    • View Profile
Re: How do I do Object3D.rotate(SimpleVector)
« Reply #17 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

Offline AGP

  • quad
  • ******
  • Posts: 1516
    • View Profile
Re: How do I do Object3D.rotate(SimpleVector)
« Reply #18 on: March 29, 2014, 07:44:46 pm »
Also, how do I convert between vecmath's Vector3f to SimpleVector?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11746
    • View Profile
    • http://www.jpct.net
Re: How do I do Object3D.rotate(SimpleVector)
« Reply #19 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
Maybe. I would take treat it as such until it turns out that it's not.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11746
    • View Profile
    • http://www.jpct.net
Re: How do I do Object3D.rotate(SimpleVector)
« Reply #20 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.

Offline AGP

  • quad
  • ******
  • Posts: 1516
    • View Profile
Re: How do I do Object3D.rotate(SimpleVector)
« Reply #21 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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11746
    • View Profile
    • http://www.jpct.net
Re: How do I do Object3D.rotate(SimpleVector)
« Reply #22 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.

Offline AGP

  • quad
  • ******
  • Posts: 1516
    • View Profile
Re: How do I do Object3D.rotate(SimpleVector)
« Reply #23 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());
« Last Edit: March 31, 2014, 04:45:11 am by AGP »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11746
    • View Profile
    • http://www.jpct.net
Re: How do I do Object3D.rotate(SimpleVector)
« Reply #24 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;
}

Offline AGP

  • quad
  • ******
  • Posts: 1516
    • View Profile
Re: How do I do Object3D.rotate(SimpleVector)
« Reply #25 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);

  }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11746
    • View Profile
    • http://www.jpct.net
Re: How do I do Object3D.rotate(SimpleVector)
« Reply #26 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.

Offline AGP

  • quad
  • ******
  • Posts: 1516
    • View Profile
Re: How do I do Object3D.rotate(SimpleVector)
« Reply #27 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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11746
    • View Profile
    • http://www.jpct.net
Re: How do I do Object3D.rotate(SimpleVector)
« Reply #28 on: April 01, 2014, 08:44:53 am »
Most likely....