jPCT - a 3d engine for Java => Projects => Topic started by: Chico de las poeías on July 03, 2009, 06:00:51 am

Title: JPCT+odejava and Skybox
Post by: Chico de las poeías on July 03, 2009, 06:00:51 am


What do you think?...  :)
Title: Re: JPCT+odejava and Skybox
Post by: EgonOlsen on July 03, 2009, 02:43:42 pm
Nice work. However, i had some trouble figuring out why the boxes in the ODE-example are actually moving until i realized that the rotation matrix you are using actually isn't a rotation matrix, but a combined transformation matrix. Without digging further into ODE or your code, i suggest to split the matrix into a rotational and a translational part somehow like so:

Code: [Select]
import com.threed.jpct.*;
import javax.swing.*;
import java.awt.*;
import javax.vecmath.Matrix4f;
import javax.vecmath.Quat4f;
import javax.vecmath.Vector3f;

 * @author Enrique Bermúdez E-mail: enbe11_3@hotmail.com

public class JPCTODE {

    public static void main(String[] args) throws Exception {
        JPCTODE JO = new JPCTODE();

    private void doIt() throws Exception {

        JFrame frame = new JFrame();
        frame.setSize(640, 480);
        ODE ode = new ODE();

        FrameBuffer fb = new FrameBuffer(640, 480, FrameBuffer.SAMPLINGMODE_NORMAL);

        World w = new World();
        w.setAmbientLight(255, 255, 255);

        TextureManager tm = TextureManager.getInstance();
        Texture base = new Texture("top.jpg");
        tm.addTexture("base", base);
        Object3D box = Primitives.getCube(2.0F);


        Object3D sp = Primitives.getCube(2.0F);

        sp.rotateY((float) Math.PI / 4f);
        box.rotateY((float) Math.PI / 4f);

        w.getCamera().moveCamera(Camera.CAMERA_MOVEOUT, 40);

        w.addLight(new SimpleVector(30, 30, 03), 30, 30, 03);

        Matrix n = new Matrix();
        Matrix m = new Matrix();

        while (frame.isActive()) {

            n.setDump(getMatrix(ode.boxBody.getQuaternion(), ode.boxBody.getPosition(), 1.0f));
            m.setDump(getMatrix(ode.boxBody2.getQuaternion(), ode.boxBody2.getPosition(), 1.0f));


            fb.clear(new Color(200, 200, 200));



    private Matrix extractRotation(Matrix m) {
      Matrix m2=m.cloneMatrix();
      m2.set(3, 0, 0);
      m2.set(3, 1, 0);
      m2.set(3, 2, 0);
      m2.set(3, 3, 1);
      return m2;
    private Matrix extractTranslation(Matrix m) {
      Matrix m2=m.cloneMatrix();
      m2.set(0, 0, 1);
      m2.set(1, 1, 1);
      m2.set(2, 2, 1);
      m2.set(1, 0, 0);
      m2.set(2, 0, 0);
      m2.set(2, 1, 0);
      m2.set(0, 1, 0);
      m2.set(0, 2, 0);
      m2.set(1, 2, 0);
      return m2;
    private float[] getMatrix(Quat4f q, Vector3f v, float f) {

        Matrix4f m = new Matrix4f(q, v, f);

        return new float[]{m.m00, m.m10, m.m20, m.m30,
                    m.m01, m.m11, m.m21, m.m31,
                    m.m02, m.m12, m.m22, m.m32,
                    -m.m03, -m.m13, -m.m23, m.m33

Giving jPCT a rotation matrix to work with that actually isn't one may bite you sooner or later...
Title: Re: JPCT+odejava and Skybox
Post by: Chico de las poeías on July 03, 2009, 06:16:42 pm
Thanks! ;D

Oviusly, you can also work with diferents shapes.
For example:
boxBody2 = new Body("box2", world, new GeomSphere("esfera",2f));
Object3D sp = Primitives.getSphere(2.0F);

(if anybody wants odejava supports, you can find it here: http://www.javagaming.org/ )