Author Topic: problem with addTriangle after build  (Read 2004 times)

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
problem with addTriangle after build
« 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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: problem with addTriangle after build
« Reply #1 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) 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.

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: problem with addTriangle after build
« Reply #2 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