www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: JavaMan on March 19, 2008, 10:48:16 pm

Title: problem with addTriangle after build
Post by: JavaMan on March 19, 2008, 10:48:16 pm
Hi, I am trying to add triangles to an object after the object has been built. I noticed that the addTriangle method call works fine, but when the object is renderered it throws an exception. Here is some code to demonstrate.
Quote
import com.threed.jpct.*;

class AddTriTest {

   public static void main(String args[])throws Exception{

   Object3D ob = new Object3D(30);
   ob.addTriangle(new SimpleVector(0,0,0),new SimpleVector(0,100,0),new SimpleVector(100,0,0));
   ob.build();
   
   World world = new World();
   world.setAmbientLight(200,200,200);

   world.addObject(ob);
   world.newCamera();
   
   Camera cam = world.getCamera();
   cam.moveCamera(Camera.CAMERA_MOVEOUT,200);
   
   FrameBuffer fb = new FrameBuffer(800,600,FrameBuffer.SAMPLINGMODE_NORMAL );
   fb.enableRenderer(IRenderer.RENDERER_OPENGL);
   fb.disableRenderer(IRenderer.RENDERER_SOFTWARE);

   world.removeObject(ob);
   ob.addTriangle(new SimpleVector(0,-100,0),new SimpleVector(0,0,0),new SimpleVector(100,-100,0));
   ob.build();
   world.addObject(ob);
         while (!org.lwjgl.opengl.Display.isCloseRequested()) {
         fb.clear();
         world.renderScene(fb);
         world.draw(fb);
         
         fb.update();
         fb.displayGLOnly();
         Thread.sleep(10);
      }
      fb.disableRenderer(IRenderer.RENDERER_OPENGL);
      fb.dispose();
      System.exit(0);
   }
}

Does addTriangle only work before calling buil?
Jman
Title: Re: problem with addTriangle after build
Post by: EgonOlsen on March 19, 2008, 11:13:42 pm
This code doesn't throw an exception for me, but the second triangle doesn't appear, which is normal behaviour. Adding a triangle after calling build() may work, but doesn't have to. To make it work, i've updated the rc3-version (http://www.jpct.net/download/beta/jpctapi116rc3.zip (http://www.jpct.net/download/beta/jpctapi116rc3.zip)) and added an unbuild()-method to Object3D which takes back some of the changes that build() applies to an object. After that, it should be possible to add the triangle and call build() again. Please give it a try.
Title: Re: problem with addTriangle after build
Post by: JavaMan on March 20, 2008, 03:32:13 am
Hey,
Thank-you!! Its works great. This is going to make my life a lot easier!!!  ;D
Jman