jPCT-AE together with own OBJ parser, rotations

Started by pieps2000, January 09, 2012, 05:48:14 PM

Previous topic - Next topic

pieps2000

Hello,

I'm using jPCT-AE together with an own OBJ parser because I also would like to render the outlines of the 3D model and I woud like to use some functions of jPCT-AE. That means: At first the 3D model (OBJ) gets parsed and rendered by jPCT-AE. And then I extract the outlines of the model with another OBJ parser and that other OBJ parser draws the outlines with GL_LINES then. After that, in the onDrawFrame function, I would like to rotate the jPCT-AE cam around both models. It only works for the 3D model which got parsed by jPCT-AE because it's an own world. Somehow the outline model is at the location of the cam then and both (outline model + cam) rotate around the 3D model. I moved already the outline model back at the coordinates of the 3D model. Now I have only a problem with the rotation of the outline model which still rotates with the cam. In other words: It looks from the view point (cam) that the 3D model rotates. But it doesn't look from the view point that the outline model rotates. I have to substract the rotations of the cam on the outline model now again.

I tried it with:
//mObject gets parsed and drawed by jPCT-AE via Loader.loadOBJ() and Object3D.mergeAll()
cam.setPositionToCenter(mObject);
cam.rotateCameraX(-rotx);
cam.moveCamera(Camera.CAMERA_MOVEOUT, 8.f);

And I tried to compensate it for the outline model with:
//outlineObject gets parsed by an own OBJ parser
gl.glTranslatef(0.f, 0.f, -8.f);  // works
gl.glRotatef(xrot, 1.f, 0.f, 0.f);  // doesn't work because of different interpretation of the angle, it rotates slower than mObject on the screen
outlineObject.draw(gl);

It seems for me that cam.rotateCameraX(-angle) calculates the angle in another way than gl.glRotatef(angle, 1.f, 0.f, 0.f).
Is there an easier way to set the same angle for both cam and outline model? I calculated already between radiant and degree, but it didn't work.
Which type of angle does cam.rotateCameraX() need?

Or do I have to calculate the origin angle back from cam.getBack() which is a little bit more difficult?

I can read answers in German and English language. Many thanks in advance!

EgonOlsen

I'm not sure if that's actually what you need, but you can try to implement an IRenderHook and put your line drawing in the before-(or after-)Rendering()-method. That way, the outline model will be rendered using the same model view matrix. However, if you start using gl-commands at that stage that fiddle around with the current matrix like glTranslate or glRotate, you will also modify the rendering of the normal model.
There's no different interpretation of the angles between jPCT-AE and OpenGL...might be because you are not taking the rotation pivot into account with your code (nor do you seem to care of that the matrix you are tweaking there actually is the model view matrix...it is by accident, because it's the last one that jPCT-AE touches, so the matrix mode remains set to model view, but i wouldn't rely on this.

pieps2000

That explains it. I missed already the forest for the trees. Many thanks for your fast answer. I will try it.