16
Support / Re: object not translating as expected?
« on: March 25, 2010, 04:14:08 pm »
Figured it out .... I wasn't setting the translation matrix correctly.
--Tim.
--Tim.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
import com.threed.jpct.*;
public class MyTest {
private static float PI = (float) Math.PI;
private World world;
private FrameBuffer buffer;
private Object3D [] box = new Object3D[3];
private Object3D plane = null;
int counter = 0;
boolean right = true;
public static void main(String[] args) throws Exception {
new MyTest().loop();
}
public MyTest() throws Exception {
world = new World();
world.setAmbientLight(255, 255, 255);
TextureManager.getInstance().addTexture("box", new Texture("box.jpg"));
TextureManager.getInstance().addTexture("ground", new Texture("cobblestones.jpg"));
for (int i=0;i<3;i++) {
box[i] = Primitives.getBox(13f, 2f);
box[i].setTexture("box");
box[i].setEnvmapped(Object3D.ENVMAP_ENABLED);
box[i].build();
world.addObject(box[i]);
box[i].setOrigin(SimpleVector.ORIGIN);
}
box[0].translate(-40,-1,0);
box[1].translate(0,-1,0);
box[2].translate(40,-1,0);
box[0].setAdditionalColor(java.awt.Color.RED);
box[1].setAdditionalColor(java.awt.Color.GREEN);
box[2].setAdditionalColor(java.awt.Color.BLUE);
plane = Primitives.getPlane(20, 30);
plane.rotateX(PI / 2f);
plane.setSpecularLighting(true);
plane.setTexture("ground");
world.addObject(plane);
plane.build();
plane.compileAndStrip();
world.getCamera().setPosition(0, -150, -500);
world.getCamera().lookAt(box[1].getTransformedCenter());
}
private void loop() throws Exception {
buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL);
SimpleVector tm = null;
while (!org.lwjgl.opengl.Display.isCloseRequested()) {
for (int i = 0; i < 3; i++) {
tm = box[i].getTranslation();
if (tm.z < -200) {
tm.z = 200;
box[i].translate(tm);
box[i].setOrigin(SimpleVector.ORIGIN);
System.out.println("RESET ORIGIN");
} else {
tm.z -= 0.1f;
box[i].translate(tm);
}
}
buffer.clear(java.awt.Color.BLUE);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.displayGLOnly();
Thread.sleep(300);
}
buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
buffer.dispose();
System.exit(0);
}
}