Author Topic: Pls Help on Default rotation pivot and behavior of rotateX, rotateY, rotateZ  (Read 2666 times)

Offline madhava.s

  • byte
  • *
  • Posts: 16
    • View Profile
i was experimenting with rotation plane around it's geometric center with mathematical X,Y,Z axis(not default Y Z axis of ) , I needed to do trial and error to get the position. Tried searching documentation, couldn't find it. Pls anybody shed some light on this, if it's already there in documentation n I have missed pls point me towards that.

Offline madhava.s

  • byte
  • *
  • Posts: 16
    • View Profile
Unalbe to upload image..as in image in hyperlink. But insteand of plane there's a jcpt plane 300X300.

http://virtualskies.arc.nasa.gov/aeronautics/images/3axis.gif


Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
You have to use object's rotation axis...

pitch...
Code: [Select]
Matrix m = object.getRotationMatrix();
SimpleVector axis = m.getXAxis();
object.rotateAxis(axis, angle);

Offline madhava.s

  • byte
  • *
  • Posts: 16
    • View Profile
Thanks thomas, Problem solved only for Y-axis. :(
For Y-axis object rotates on center where as for Z & X axes plane circles around a point out it's bounds. pasting code below.

Code: [Select]
Matrix m = object.getRotationMatrix();
        SimpleVector objectAxis ;
        switch(axis){
            case X_AXIS:objectAxis=m.getXAxis();
                        objectAxis.add(object.getCenter());
                        object.rotateAxis(objectAxis, radians);
                        break;                       
               
            case Y_AXIS:objectAxis=m.getYAxis();
                        objectAxis.add(object.getCenter());
                        object.rotateAxis(objectAxis,radians);
                        break;
               
            case Z_AXIS:objectAxis=m.getZAxis();
                        objectAxis.add(object.getCenter());
                        object.rotateAxis(objectAxis,radians);
                        break;
        }


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12065
    • View Profile
    • http://www.jpct.net
What is this

Code: [Select]
objectAxis.add(object.getCenter());

supposed to do?

Offline madhava.s

  • byte
  • *
  • Posts: 16
    • View Profile
Tried to translate vector from origin to Geometric center. I was thinking this will give us vector parallel to absolute axes.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12065
    • View Profile
    • http://www.jpct.net
Tried to translate vector from origin to Geometric center. I was thinking this will give us vector parallel to absolute axes.
That makes no sense. The rotation happens in object space around the given axis with the rotation pivot as position vector. Place the rotation pivot inside of your plane (in object space, NOT in world space) and simply rotate around the result of get?Axis(). Don't translate the returned vector.

Offline madhava.s

  • byte
  • *
  • Posts: 16
    • View Profile
Removed translation code still behavior is same . I'm using below code to set Rotation Pivot
Code: [Select]
                float[] bounds=layer1.getMesh().getBoundingBox();
                layer1.setCenter(SimpleVector.create(
                (bounds[0]+bounds[1])/2,
                (bounds[2]+bounds[3])/2,
                (bounds[4]+bounds[5])/2));
        layer1.setRotationPivot(layer1.getCenter());
Anything wrong here?


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12065
    • View Profile
    • http://www.jpct.net
Maybe we should take one step back and clarify what your actual problem is. because i'm not quite sure anymore. Is the problem that you don't know where to place the rotation pivot or that you are having trouble to rotate around the correct axis?

Offline madhava.s

  • byte
  • *
  • Posts: 16
    • View Profile
Problem is i'm unable rotate around axis , but don't know where have I gone wrong in placing the Rotation pivot or rotating the axis.

Offline madhava.s

  • byte
  • *
  • Posts: 16
    • View Profile
Thanks Egon and Thanks to paul for his examples. Dummy object did the trick
Code: [Select]
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jcptexp;

import com.threed.jpct.*;
import java.awt.Color;

public class JcptExp {
   
    public static void main(String[] args) {
                World w = new World();
FrameBuffer fb = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
fb.disableRenderer(IRenderer.RENDERER_SOFTWARE);
fb.enableRenderer(IRenderer.RENDERER_OPENGL);
                Object3D dummy=Object3D.createDummyObj();
Object3D toy= Primitives.getCube(1);
Object3D toy2=Primitives.getPlane(2, 10f);


toy.setScale(0.5f);
toy2.setScale(2f);

toy.setAdditionalColor(Color.BLUE);
toy2.setAdditionalColor(Color.YELLOW);
toy2.setEnvmapDirection(Object3D.ENVMAP_XZ);
                toy2.rotateAxis(toy2.getRotationMatrix().getXAxis(), -0.3f);
                toy2.rotateAxis(toy2.getRotationMatrix().getYAxis(),0.2f);
                toy2.rotateAxis(toy2.getRotationMatrix().getYAxis(), -0.2f);
w.getCamera().moveCamera(Camera.CAMERA_MOVEOUT, 100);
w.getCamera().moveCamera(Camera.CAMERA_MOVEUP, 50);
                w.getCamera().setOrientation(SimpleVector.create(1,0,0), SimpleVector.create(0,-1,0));
                w.getCamera().align(toy2);
w.setAmbientLight(130, 130, 130);
                toy2.setOrientation(SimpleVector.create(1,0,0), SimpleVector.create(0,-1,0));
                dummy.setOrientation(SimpleVector.create(1,0,0), SimpleVector.create(0,-1,0));
                toy2.rotateZ(0.01f);
toy.build();
toy2.build();
float[] bounds=toy2.getMesh().getBoundingBox();
toy.addParent(toy2);
toy2.addParent(dummy);
w.addObject(toy);
w.addObject(toy2);

w.getCamera().lookAt(toy.getTransformedCenter());

offset(toy2, new SimpleVector(2,2,0));

                int i=-1;
while(!org.lwjgl.opengl.Display.isCloseRequested()) {
                        i*=-1;
                        //dummy.setRotationPivot(SimpleVector.create(i*0.001f,0,0));
                        dummy.rotateAxis(dummy.getRotationMatrix().getYAxis(),-0.0002f);
fb.clear(Color.RED);
w.renderScene(fb);
w.draw(fb);
fb.update();
fb.displayGLOnly();

                        try {
//Thread.sleep(100);
} catch(Exception e) {}

                       


}
fb.dispose();
System.exit(0);
}

static private void offset(Object3D which, SimpleVector amount) {
Matrix mb=which.getTranslationMatrix();
which.setTranslationMatrix(new Matrix());
which.translate(amount);
which.translateMesh();
which.setTranslationMatrix(mb);
}

}