181
Support / Re: Help with CollisionDetection !!!
« on: March 11, 2008, 01:55:36 pm »
Hey, thanks, that got it to work. I made the boxes smaller. That config class sure is important.!!
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 java.awt.*;
import javax.swing.*;
import com.threed.jpct.*;
import org.lwjgl.opengl.*;
class CanTest {
public static void main(String args[])throws Exception{
Config.farPlane=500000;
final JPanel top = new JPanel();
final World w = new World();
Object3D o = new Object3D(200);
Object3D box1 = Primitives.getCube(60);
Object3D box2 = Primitives.getCube(60);
box1.build();
box2.build();
box1.translate(900,0,0);
box1.translateMesh();
box1.build();
box1.addCollisionListener(new Lis());
box2.addCollisionListener(new Lis());
box1.setTransparency(0);
box2.setTransparency(0);
box1.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS|Object3D.COLLISION_CHECK_SELF);
box2.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS|Object3D.COLLISION_CHECK_SELF);
w.addObject(box1);
w.addObject(box2);
box1.setAdditionalColor(Color.red);
box2.setAdditionalColor(Color.blue);
w.setAmbientLight(200,200,200);
w.newCamera();
Camera cam = w.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT,5000);
cam.moveCamera(Camera.CAMERA_MOVERIGHT,800);
final FrameBuffer b = new FrameBuffer(800,600,FrameBuffer.SAMPLINGMODE_NORMAL);
b.enableRenderer(IRenderer.RENDERER_OPENGL,FrameBuffer.SAMPLINGMODE_NORMAL );
b.disableRenderer(IRenderer.RENDERER_SOFTWARE);
box1.enableCollisionListeners();
box2.enableCollisionListeners();
int i = 0;
while(i<5000){
b.clear();
w.renderScene(b);
w.draw(b);
b.update();
b.displayGLOnly();
Thread.sleep(100);
SimpleVector v = box1.checkForCollisionSpherical(new SimpleVector(-10f,0,0),10f);
box1.translate(v.x,v.y,v.z);
System.out.println("" + v.x + " " + v.y + " " + v.z);
}
}
}
class Lis implements CollisionListener {
public void collision(CollisionEvent e){
System.out.println("OUCH!!!!!!!!!!!!");
}
public boolean requiresPolygonIDs(){
return false;
}
}
Which LWJGL version are you using?
Does it help to make the JPanel invisible before trying to remove the canvas?
BTW: What is the purpose of the new FrameBuffer instance in that code?
In fact I guess that many people has this problem when trying to quit jpct apps since using java 6.Huh,thats weird. Maybe I'll try it out with jre 1.5 instead.
import java.awt.*;
import javax.swing.*;
import com.threed.jpct.*;
class CanTest {
public static void main(String args[]){
final JPanel top = new JPanel();
World w = new World();
Object3D o = new Object3D(200);
o.addTriangle(new SimpleVector(0,0,0),new SimpleVector(0,300,0),new SimpleVector(300,0,0));
o.build();
w.addObject(o);
w.setAmbientLight(200,200,200);
w.newCamera();
Camera cam = w.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT,100);
JFrame f = new JFrame();
f.setLayout(new GridLayout(1,1));
f.add(top);
f.setVisible(true);
f.setSize(500,500);
top.setBackground(Color.blue);
try{ Thread.sleep } catch(Exception e){}
FrameBuffer b = new FrameBuffer(top.getWidth(),top.getHeight(),FrameBuffer.SAMPLINGMODE_NORMAL);
final Canvas c = b.enableGLCanvasRenderer();
b.disableRenderer(IRenderer.RENDERER_SOFTWARE);
top.setLayout(new GridLayout(1,1));
top.add(c);
int i = 0;
i=0;
while(i<5000){
b.clear();
//System.out.println("RENDERSCENE");
w.renderScene(b);
//System.out.println("DRAW");
w.draw(b);
//System.out.println("UPDATE");
b.update();
//System.out.println("GLONLY");
b.displayGLOnly();
//System.out.println("CANVAS__REPAINT");
c.repaint();
System.out.println("" + ++i);
}
b.dispose();
FrameBuffer framebuffer =new FrameBuffer(top.getWidth(),top.getHeight(),FrameBuffer.SAMPLINGMODE_NORMAL);
System.out.println("E");
System.out.println("l1");
framebuffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
System.out.println("About to crash...");
/** Uncommenting the line below makes the program crash. */
//top.remove(c);
/**It doesn't matter is you try this. Still the same result: a crash*/
/*
SwingUtilities.invokeLater(new Runnable(){
public void run(){
top.remove(c);
}
});
*/
}
}
About to crash...
#
# An unexpected error has been detected by Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x696a0508, pid=3752, tid=2748
#
# Java VM: Java HotSpot(TM) Client VM (1.6.0_03-b05 mixed mode, sharing)
# Problematic frame:
# C [nvoglnt.dll+0x1a0508]
#
# An error report file with more information is saved as hs_err_pid3752.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
[error occurred during error reporting, step 270, id 0xc0000005]
Some menus are not usable on 1280*1024, because the 3d canvas is rendered on top them them.I noticed that, but forgot about fixing. It is now fixed.
Apart from that, i'm unable to add create something that is actually visible in the 3d canvas. Can you give short step-by-step-introduction of how to add a primitive and view it (for example a cube)? I managed to add a cube (at least i think so), it's just that i don't see it in the canvas!?
And I was wondering if you had tried the Eclipse editor and what you thought about it.