www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: madhava.s on January 29, 2013, 10:43:12 am

Title: Pls Help on Default rotation pivot and behavior of rotateX, rotateY, rotateZ
Post by: madhava.s on January 29, 2013, 10:43:12 am
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.
Title: Re: Pls Help on Default rotation pivot and behavior of rotateX, rotateY, rotateZ
Post by: madhava.s on January 29, 2013, 11:08:24 am
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 (http://virtualskies.arc.nasa.gov/aeronautics/images/3axis.gif)

Title: Re: Pls Help on Default rotation pivot and behavior of rotateX, rotateY, rotateZ
Post by: Thomas. on January 29, 2013, 11:43:13 am
You have to use object's rotation axis...

pitch...
Code: [Select]
Matrix m = object.getRotationMatrix();
SimpleVector axis = m.getXAxis();
object.rotateAxis(axis, angle);
Title: Re: Pls Help on Default rotation pivot and behavior of rotateX, rotateY, rotateZ
Post by: madhava.s on January 30, 2013, 10:38:51 am
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;
        }

Title: Re: Pls Help on Default rotation pivot and behavior of rotateX, rotateY, rotateZ
Post by: EgonOlsen on January 30, 2013, 11:09:59 am
What is this

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

supposed to do?
Title: Re: Pls Help on Default rotation pivot and behavior of rotateX, rotateY, rotateZ
Post by: madhava.s on January 30, 2013, 06:29:30 pm
Tried to translate vector from origin to Geometric center. I was thinking this will give us vector parallel to absolute axes.
Title: Re: Pls Help on Default rotation pivot and behavior of rotateX, rotateY, rotateZ
Post by: EgonOlsen on January 30, 2013, 07:47:20 pm
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.
Title: Re: Pls Help on Default rotation pivot and behavior of rotateX, rotateY, rotateZ
Post by: madhava.s on January 31, 2013, 04:35:49 am
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?

Title: Re: Pls Help on Default rotation pivot and behavior of rotateX, rotateY, rotateZ
Post by: EgonOlsen on January 31, 2013, 08:11:03 am
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?
Title: Re: Pls Help on Default rotation pivot and behavior of rotateX, rotateY, rotateZ
Post by: madhava.s on February 01, 2013, 05:34:45 am
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.
Title: Re: Pls Help on Default rotation pivot and behavior of rotateX, rotateY, rotateZ
Post by: madhava.s on February 08, 2013, 06:59:42 am
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);
}

}