Hi,
I have just come from work was going to write it now, but I see you have already reproduced it.
Thanks,
Wojtek
I have just come from work was going to write it now, but I see you have already reproduced it.
Thanks,
Wojtek
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.
Show posts Menu
public Ray()
{
super(4);
for (int i = 0; i < VERTEXES.length; ++i)
vertexes[i] = new SimpleVector(VERTEXES[i]);
addTriangle(VERTEXES[HF1], 1, 1, VERTEXES[HT1], 1, 0, VERTEXES[HT2], 0, 0);
addTriangle(VERTEXES[HT2], 0, 0, VERTEXES[HF2], 0, 1, VERTEXES[HF1], 1, 1);
addTriangle(VERTEXES[VF1], 1, 1, VERTEXES[VT1], 1, 0, VERTEXES[VT2], 0, 0);
addTriangle(VERTEXES[VT2], 0, 0, VERTEXES[VF2], 0, 1, VERTEXES[VF1], 1, 1);
setCulling(Object3D.CULLING_DISABLED);
setLighting(Object3D.LIGHTING_NO_LIGHTS);
setTransparency(0);
build();
getMesh().setVertexController(new RayVertexController(),
IVertexController.PRESERVE_SOURCE_MESH);
compile(true);
}
public void initialize(SimpleVector from, SimpleVector to, double scale, Color color,
int transparencyMode)
{
setVertexes(from, to, (float) scale);
setAdditionalColor(color);
setTransparencyMode(transparencyMode);
getMesh().applyVertexController();
touch();
setCenter(SimpleVector.ORIGIN);
setOrigin(SimpleVector.ORIGIN);
getRotationMatrix().setIdentity();
setRotationPivot(SimpleVector.ORIGIN);
}
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import com.threed.jpct.Camera;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.World;
public class Test extends JFrame implements Runnable
{
private static final long serialVersionUID = 811111147457394977L;
private World world;
private FrameBuffer buffer;
private Canvas myCanvas;
private boolean alive = true;
private boolean initialized = false;
private Ray ray;
private Object3D box;
public static void main(String[] args)
{
new Test();
}
public Test()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
init();
pack();
setVisible(true);
}
public void init()
{
world = new World();
ray = new Ray();
ray.initialize(new SimpleVector(-20, 0, -3), new SimpleVector(0, -20,
-3), 0.5, Color.YELLOW, Object3D.TRANSPARENCY_MODE_DEFAULT);
box = Primitives.getBox(2, 2);
box.setBillboarding(true);
box.setAdditionalColor(Color.WHITE);
box.setLighting(Object3D.LIGHTING_NO_LIGHTS);
box.setTransparency(0);
box.setTransparencyMode(Object3D.TRANSPARENCY_MODE_ADD);
box.setTransparency(255);
box.setScale(6);
box.build();
box.compile();
box.translate(-150, -150, -40);
world.addObject(ray);
world.addObject(box);
Camera camera = world.getCamera();
camera.setPosition(0, 0, 0);
camera.lookAt(box.getTransformedCenter());
world.setAmbientLight(100, 100, 100);
buffer = new FrameBuffer(640, 480, FrameBuffer.SAMPLINGMODE_GL_AA_4X);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
myCanvas = buffer.enableGLCanvasRenderer();
add(myCanvas, BorderLayout.CENTER);
initialized = true;
new Thread(this).start();
}
@Override
public void run()
{
while (alive)
{
this.repaint();
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
}
}
alive = false;
}
@Override
public void paint(Graphics g)
{
if (!initialized)
return;
buffer.clear();
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.displayGLOnly();
myCanvas.repaint();
}
}
public class Ray extends Object3D
{
private static final long serialVersionUID = -1684665440334869826L;
private static final SimpleVector YVEC = new SimpleVector(0, 1, 0);
private static final SimpleVector ZVEC = new SimpleVector(0, 0, 1);
private static int HF1 = 0;
private static int HF2 = 1;
private static int HT1 = 2;
private static int HT2 = 3;
private static int VF1 = 4;
private static int VF2 = 5;
private static int VT1 = 6;
private static int VT2 = 7;
private static SimpleVector[] VERTEXES = new SimpleVector[] {
new SimpleVector(-1.5, -1.5, -1), new SimpleVector(-0.5, -0.5, -1),
new SimpleVector(1.5, 1.5, -1), new SimpleVector(0.5, 0.5, -1),
new SimpleVector(-1, -1, -1.5), new SimpleVector(-0.5, -0.5, -0.5),
new SimpleVector(1.5, 1.5, 1.5), new SimpleVector(0.5, 0.5, 0.5) };
private SimpleVector[] vertexes = new SimpleVector[VERTEXES.length];
public Ray()
{
super(4);
for (int i = 0; i < VERTEXES.length; ++i)
vertexes[i] = new SimpleVector(VERTEXES[i]);
addTriangle(VERTEXES[HF1], 1, 1, VERTEXES[HT1], 1, 0, VERTEXES[HT2], 0,
0);
addTriangle(VERTEXES[HT2], 0, 0, VERTEXES[HF2], 0, 1, VERTEXES[HF1], 1,
1);
addTriangle(VERTEXES[VF1], 1, 1, VERTEXES[VT1], 1, 0, VERTEXES[VT2], 0,
0);
addTriangle(VERTEXES[VT2], 0, 0, VERTEXES[VF2], 0, 1, VERTEXES[VF1], 1,
1);
setCulling(Object3D.CULLING_DISABLED);
setLighting(Object3D.LIGHTING_NO_LIGHTS);
setTransparency(0);
build();
getMesh().setVertexController(new RayVertexController(),
IVertexController.PRESERVE_SOURCE_MESH);
}
public void initialize(SimpleVector from, SimpleVector to, double scale, Color color,
int transparencyMode)
{
setVertexes(from, to, (float) scale);
setAdditionalColor(color);
setTransparencyMode(transparencyMode);
getMesh().applyVertexController();
setCenter(SimpleVector.ORIGIN);
setOrigin(SimpleVector.ORIGIN);
getRotationMatrix().setIdentity();
setRotationPivot(SimpleVector.ORIGIN);
}
private void setVertexes(SimpleVector from, SimpleVector to, float scale)
{
scale /= 2;
SimpleVector diff = to.calcSub(from);
SimpleVector ya = SimpleVectorUtil.mul(
diff.calcCross(YVEC).normalize(), scale);
SimpleVector za = SimpleVectorUtil.mul(
diff.calcCross(ZVEC).normalize(), scale);
vertexes[HF1].set(from.x - ya.x, from.y - ya.y, from.z - ya.z);
vertexes[HF2].set(from.x + ya.x, from.y + ya.y, from.z + ya.z);
vertexes[HT1].set(to.x - ya.x, to.y - ya.y, to.z - ya.z);
vertexes[HT2].set(to.x + ya.x, to.y + ya.y, to.z + ya.z);
vertexes[VF1].set(from.x - za.x, from.y - za.y, from.z - za.z);
vertexes[VF2].set(from.x + za.x, from.y + za.y, from.z + za.z);
vertexes[VT1].set(to.x - za.x, to.y - za.y, to.z - za.z);
vertexes[VT2].set(to.x + za.x, to.y + za.y, to.z + za.z);
}
public SimpleVector convertVertex(SimpleVector vertex)
{
for (int i = 0; i < VERTEXES.length; ++i)
if (VERTEXES[i].equals(vertex))
return vertexes[i];
return vertex;
}
class RayVertexController extends GenericVertexController
{
private static final long serialVersionUID = -3596694596175935772L;
@Override
public void apply()
{
SimpleVector[] src = getSourceMesh();
SimpleVector[] dst = getDestinationMesh();
for (int i = 0; i < src.length; ++i)
{
dst[i].set(convertVertex(src[i]));
}
}
}
}
public class SimpleVectorUtil
{
public static SimpleVector mul(SimpleVector vec, float mul)
{
vec.x *= mul;
vec.y *= mul;
vec.z *= mul;
return vec;
}
public static SimpleVector calcMul(SimpleVector vec, float mul)
{
return mul(new SimpleVector(vec), mul);
}
}
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.World;
public class Test2 extends JFrame implements Runnable
{
private static final long serialVersionUID = -1203822572518219468L;
private World world;
private FrameBuffer buffer;
private Canvas canvas;
private boolean initialized = false;
private FrameBuffer buffer2;
private Canvas canvas2;
private World world2;
private boolean alive = true;
public static void main(String[] args)
{
new Test2();
}
public Test2()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
init();
pack();
setVisible(true);
}
private static World createWorld()
{
World w = new World();
w.setAmbientLight(100, 100, 100);
w.getCamera().setPosition(new SimpleVector(200, 0, 0));
w.getCamera().lookAt(SimpleVector.ORIGIN);
return w;
}
public void init()
{
world = createWorld();
world2 = createWorld();
Object3D BLUEPRINT = Primitives.getPyramide(10);
Object3D o1 = BLUEPRINT.cloneObject();
o1.compileAndStrip();
world.addObject(o1);
Object3D o2 = BLUEPRINT.cloneObject();
o2.compileAndStrip();
world2.addObject(o2);
buffer = createBuffer();
buffer2 = createBuffer();
add(canvas = buffer.enableGLCanvasRenderer(), BorderLayout.LINE_START);
add(canvas2 = buffer2.enableGLCanvasRenderer(), BorderLayout.LINE_END);
initialized = true;
new Thread(this).start();
}
private static FrameBuffer createBuffer()
{
FrameBuffer buffer = new FrameBuffer(300, 300,
FrameBuffer.SAMPLINGMODE_GL_AA_4X);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
return buffer;
}
@Override
public void run()
{
while (alive)
{
this.repaint();
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
}
}
alive = false;
}
private static void paint(FrameBuffer buffer, World world, Canvas canvas)
{
buffer.clear(Color.BLACK);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.displayGLOnly();
canvas.repaint();
}
@Override
public void paint(Graphics g)
{
if (!initialized)
return;
paint(buffer, world, canvas);
paint(buffer2, world2, canvas2);
}
}
QuoteThis one: http://www.jpct.net/download/beta/jpct.jar.Thanks
QuoteAbout the excpetion...might be a problem with multiple threads working on the objects.Hmm, the thread that sets the new Object3D to the world is called AWT-EventQueue-0 (this is a handler method for click on grid's row). The thread where an exception is thrown is also called the same, but eclipse debugger shows that this is another thread. I do not know AWT/swing much so I cannot say why I have multiple threads for that (perhaps because eclipse stopped threads that thrown an exception so AWT created another one?)... But I will try to investigate it a little bit more...
QuoteI'm not sure what the problem with sharing and stripping might be in your case. Any exceptions or something? In case of sharing, make sure that you are sharing with objects that live in the same context, i.e. not with the blue print object from your factory, because that will cause this object to be compiled using the gl context of the first objects that shares data with it...and all others will try to reuse it and that will work only if you are in the same context.Oh ok, so this must occur because I am using one blueprint as a clone source for objects that belongs to different contexts.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
Additional visibility list (2) created with size: 10000
at com.threed.jpct.CompiledInstance.fill(Unknown Source)
at com.threed.jpct.Object3DCompiler.compile(Unknown Source)
at com.threed.jpct.VersionHelper5.compile(Unknown Source)
at com.threed.jpct.World.renderScene(Unknown Source)
at game.ui.swing.components.jpct.JPCTPanel.renderContent(JPCTPanel.java:128)
at game.ui.swing.components.jpct.ShipFlightPanel.processBackground(ShipFlightPanel.java:157)
at game.ui.swing.views.gameWindow.FlightView.updateView(FlightView.java:74)
at game.ui.swing.views.GameWindowView.updateViews(GameWindowView.java:396)
at game.ui.swing.views.GameWindowView.access$4(GameWindowView.java:387)
at game.ui.swing.views.GameWindowView$6$1.run(GameWindowView.java:378)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
QuoteAdditionally, initialization has to happen in the paintGL-method of the renderer, so there's no way to do this beforehand, even if you are already in the EDT. However, it may be sufficient to skip the wait if we are already in the EDT. I've updated the jar in link a few posts ealier with a version that does this (hopefully).Ok, I understand. In the meantime I have reduced the amount of reinitialization of the FrameBuffers on resize event, so now each canvas is initialzied only once. Additionally I noticed that the problem with waiting was related to the fact, that I was adding a new object to world (and run compile() on it) and reinitializing a FB in the same time (both operations were a result of the same event). Now I ensured that the canvas size is not changed in that time and now it seems to work ok.
QuoteBTW: Are you actually using the same objects multiple times in different views? I don't think that this will work if you are using display lists (what you do, juding from the log), because they are bound to the gl context which should be different in multiple canvas'. Or does it work anyway? I 'm just asking because i never really tried this...and hoped that nobody never will, so that i would never have to care about this case...
Quote
Looking at the code again, it might work with multiple contexts, because it tries to revert to normal vertex arrays in that case (which are somewhat slower, but not bound to the context). However, the current version might spam the log in that case. I've modified the jar again to prevent this (if it actually is a problem in your case).
public Object3D createObject()
{
Object3D result = object.cloneObject(); //it is the model
result.compile();
return result;
}
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: java.lang.NullPointerException
at com.threed.jpct.AWTJPCTCanvas.paintGL(Unknown Source)
at org.lwjgl.opengl.AWTGLCanvas.paint(AWTGLCanvas.java:288)
at org.lwjgl.opengl.AWTGLCanvas.update(AWTGLCanvas.java:317)
at sun.awt.RepaintArea.updateComponent(Unknown Source)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at com.threed.jpct.CompiledInstance.render(Unknown Source)
at com.threed.jpct.AWTGLRenderer.drawVertexArray(Unknown Source)
... 15 more
Java version is: 1.6.0_17
-> support for BufferedImage
Version helper for 1.5+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Using LWJGL's AWTGLCanvas
Software renderer disposed
[6 times]
Driver is: vga/6.0.6001.18000 on NVIDIA Corporation / GeForce 9650M GT/PCI/SSE2
GL_ARB_texture_env_combine supported and used!
FBO supported and used!
OpenGL renderer initialized (using 4 texture stages)
[3 times]
Software renderer disposed
Software renderer disposed
Software renderer disposed
Adding Lightsource: 1
Adding Lightsource: 2
Visibility lists disposed!
Java version is: 1.6.0_17
-> support for BufferedImage
Version helper for 1.5+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Using LWJGL's AWTGLCanvas
Software renderer disposed
Waiting for renderer to initialize...0
[...]
Waiting for renderer to initialize...49
Subobject of object 15153/object15155 compiled using 612 vertices in 6ms!
Subobject of object 15153/object15155 compiled using 2 vertices in 0ms!
Object 15153/object15155 compiled to 2 subobjects in 2518ms!
Waiting for renderer to initialize...0
[...]
Waiting for renderer to initialize...49
Subobject of object 15154/object15156 compiled using 512 vertices in 1ms!
Object 15154/object15156 compiled to 1 subobjects in 2511ms!
Waiting for renderer to initialize...0
[...]
Waiting for renderer to initialize...49
Subobject of object 15177/object15179 compiled using 512 vertices in 1ms!
Object 15177/object15179 compiled to 1 subobjects in 2508ms!
Waiting for renderer to initialize...0
[...]
Waiting for renderer to initialize...49
Subobject of object 15200/object15202 compiled using 24 vertices in 0ms!
Object 15200/object15202 compiled to 1 subobjects in 2502ms!
Waiting for renderer to initialize...0
[...]
Waiting for renderer to initialize...49
Subobject of object 15201/object15203 compiled using 24 vertices in 0ms!
Object 15201/object15203 compiled to 1 subobjects in 2500ms!
Driver is: vga/6.0.6001.18000 on NVIDIA Corporation / GeForce 9650M GT/PCI/SSE2
GL_ARB_texture_env_combine supported and used!
FBO supported and used!
OpenGL renderer initialized (using 4 texture stages)
Compiled 6 display lists!
Software renderer disposed
QuoteNo, you can't initialize it when creating the FrameBuffer, because it has to happen in the awt event dispatch thread.How about running that initialization from a method invoked in a awt event dispatch thread before displaying window?
QuoteThis is what the object compiler has to wait for. To make it happen, it calls repaint() on the canvas and waits 50ms for this to happen.
world.renderScene(buffer);
from awt event dispatch thread (a timer callback), so the compiler may wait for the same thread it is working in.
Using LWJGL's AWTGLCanvas
Software renderer disposed
Waiting for renderer to initialize...0
Waiting for renderer to initialize...1
Waiting for renderer to initialize...2
[...]
Waiting for renderer to initialize...48
Waiting for renderer to initialize...49
Subobject of object 15129/object15131 compiled using 670 vertices in 1ms!
buffer = new FrameBuffer(currentWidth, currentHeight, FrameBuffer.SAMPLINGMODE_GL_AA_4X);
canvas = buffer.enableGLCanvasRenderer();
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
Java version is: 1.6.0_17
-> support for BufferedImage
Version helper for 1.5+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Using LWJGL's AWTGLCanvas
Can't find desired videomode (1232 x 555 x 32) - searching for alternatives
Can't find alternative videomode (1232 x 555 x 32) - trying something else
[ Mon Mar 15 19:58:05 CET 2010 ] - ERROR: Can't find any suitable videomode!
[ Mon Mar 15 19:58:05 CET 2010 ] - ERROR: Can't set videomode - try different settings!
Software renderer disposed
Driver is: vga/6.0.6001.18000 on NVIDIA Corporation / GeForce 9650M GT/PCI/SSE2
GL_ARB_texture_env_combine supported and used!
FBO supported and used!
OpenGL renderer initialized (using 4 texture stages)
Quote from: EgonOlsen on November 29, 2009, 08:36:06 PM
Yes, you can use the calcMinDistance that you are calling anyway for this. calcMinDistance triggers a CollisionEvent if a CollisionListener is assigned to the object...so just implement a CollisionListener (don't forget to let your requiresPolygonIDs() -impl return true), add it to all objects and you can get object and polygon id from the event.
SimpleVector ray = Interact2D.reproject2D3D(camera, buffer, mouseX, mouseY);
Object[] result = getWorld().calcMinDistanceAndObject3D(camera.getPosition(), ray, HORIZON_RADIUS);
return (Object3D) result[1];
Page created in 0.326 seconds with 13 queries.