How do I do Object3D.rotate(SimpleVector)

Started by AGP, March 27, 2014, 03:40:47 AM

Previous topic - Next topic

EgonOlsen

Quote from: AGP on March 28, 2014, 11:23:37 PM
I had to decompile to find out the name of the method. :- )
Why not start using a decent IDE (Eclipse, Netbeans...) instead... ???

AGP

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.


AGP

Also, how do I convert between vecmath's Vector3f to SimpleVector?

EgonOlsen

Quote from: 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
Maybe. I would take treat it as such until it turns out that it's not.

EgonOlsen

Quote from: AGP on March 29, 2014, 07:44:46 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.

AGP

Which ones should I negate? I'm not asking because I'm lazy, I'm asking because I really don't know...

EgonOlsen

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.

AGP

#23
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?


nativeRot = ball.getRotationMatrix().getXAxis();
nativeRot.add(ball.getRotationMatrix().getYAxis());
nativeRot.add(ball.getRotationMatrix().getZAxis());

EgonOlsen

No, it's more likely something like this:


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;
}

AGP

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.


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



  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);

  }

EgonOlsen

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.

AGP

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?

EgonOlsen