### Show Posts

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.

### Messages - dunkedbiscuit

Pages: [1] 2
1
##### Support / Re: Vector calculation
« on: January 29, 2012, 10:35:33 pm »
Not to worry. The positions didn't work as expected because there we some zeros in the SimpleVectors I was calculating the direction vector with. A satisfactory outcome.

2
##### Support / Re: Vector calculation
« on: January 29, 2012, 05:53:39 pm »
Well, here's what I'm doing so far. I calculate a cross product vector between the two points on the line, and then I get the direction vector between the first point (this) and the cross product vector.

Code: [Select]
`SimpleVector crossProduct = new SimpleVector( this.calcCross(otherNode) );            SimpleVector directionVector = new SimpleVector(                    crossProduct.x - this.x,                    crossProduct.y - this.y,                    crossProduct.z - this.z );`
I then draw a line between the cross product and the first point using Java2D and Interact2D. I also draw a line between the first point (this) and the last point of the line (otherNode). I then draw the cross product point at the end of the line betwen the cross product and the first point, and the first point at the other end. Next, I multiply the directionVector by 0.5 using scalarMul and draw its position as a point.

The problem is that this new directionVector does not rest on the line between crossProduct and the first point (this). I think that the scalarMul somehow skews it and I don't know how to fix it. This is really the crux of my problem.

3
##### Support / Re: Vector calculation
« on: January 28, 2012, 07:35:39 pm »
OK. Do you have any source code?

4
##### Support / Re: Vector calculation
« on: January 28, 2012, 03:09:39 pm »
Basically, I have a line already (as in the direction vector), and I want to create a copy of it, but translated an arbitrary distance from the original line, making it parallel with the original line. My vector math is horrible!

5
##### Support / Re: Vector calculation
« on: January 28, 2012, 12:28:43 am »
Not really, what would be ideal would be to align a place with the direction vector, so that both ends are touching the end points of the line, and the z coordinates of the plane's verts at each end of the line to be identical, so it would be level. Sort of like building a ramp.

6
##### Support / Vector calculation
« on: January 27, 2012, 09:59:50 pm »
Hi

I have two SimpleVectors, with which I create a direction vector. I will use this direction vector draw a line between the two SimpleVectors. I want to draw multiple lines that are parallel to this line, and with a bit of distance between them. Does anyone know how I could do this?

Many thanks

7
##### Support / Re: Isometric 3D in JPanel
« on: January 12, 2012, 12:55:41 pm »
Lol. I guess you're right. I'll have to look at the source for the Interact2D methods. Perhaps a orthogonal mode would be something for a new release?

8
##### Support / Re: Isometric 3D in JPanel
« on: January 12, 2012, 10:53:03 am »
Got it to work! It seems I forgot to use the framebuffer's setPaintListenerState() method to activate the IPaintListener. Thanks for your help. Do you know how to add a box where the axis lines are being drawn, i.e. in the centre of them, so that I can see if the view is truly isometric? Further, will object selection through Interact2D continue to work with the isometric view, and if so, how could I implement it to select objects in isometric view?

9
##### Support / Re: Isometric 3D in JPanel
« on: January 12, 2012, 09:59:21 am »
I've added one, and now I can see the cube. However, the code in startPainting and finishedPainting isn't being called.

Code: [Select]
`package orthogonal_test;import com.threed.jpct.*;import org.lwjgl.opengl.GL11;import javax.swing.*;import java.awt.*;/** * A simple HelloWorld using the OpenGL-renderer. * @author EgonOlsen * */public class Main implements IPaintListener { private World world; private FrameBuffer buffer; private Object3D box;        private Camera cam; public static void main(String[] args) throws Exception { new Main().loop(); } public Main() throws Exception { world = new World(); world.setAmbientLight(0, 255, 0); box = Primitives.getBox(1f, 1f); box.build(); world.addObject(box);                float dist = 30f;                cam = world.getCamera();                cam.setPosition( new SimpleVector( dist, dist, dist ) );                cam.lookAt( box.getTransformedCenter() ); } private void loop() throws Exception { buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL); buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE); buffer.enableRenderer(IRenderer.RENDERER_OPENGL, IRenderer.MODE_OPENGL);                buffer.setPaintListener(this);                JFrame frame = new JFrame();                frame.setSize( 800, 600 );                frame.setResizable(false);                Canvas canvas = buffer.enableGLCanvasRenderer();                frame.add(canvas);                frame.setVisible(true);                frame.setDefaultCloseOperation( JFrame.HIDE_ON_CLOSE );                while ( frame.isVisible() ) { buffer.clear(java.awt.Color.BLACK); world.renderScene(buffer); world.draw(buffer); buffer.update(); buffer.displayGLOnly();                        canvas.repaint(); Thread.sleep(10); } buffer.disableRenderer(IRenderer.RENDERER_OPENGL); buffer.dispose(); System.exit(0); }        public void startPainting()        {            System.out.println("here");            GL11.glMatrixMode(GL11.GL_PROJECTION);            GL11.glLoadIdentity();            GL11.glOrtho(-13, 13, -1, 10, -30, 100);            GL11.glMatrixMode(GL11.GL_MODELVIEW);            GL11.glLoadIdentity();            GL11.glRotatef(35.264f, 1.0f, 0.0f, 0.0f);            GL11.glRotatef(-45.0f, 0.0f, 1.0f, 0.0f);            GL11.glScalef(1.0f, 1.0f, -1.0f);            GL11.glTranslatef( 0, 0, 0 );            GL11.glBegin(GL11.GL_LINES);            GL11.glColor3f(1.0f, 0.0f, 0.0f);            GL11.glVertex3d(0, 0, 0);            GL11.glVertex3d(10, 0, 0);            GL11.glEnd();            GL11.glBegin(GL11.GL_LINES);            GL11.glColor3f(0.0f, 1.0f, 0.0f);            GL11.glVertex3d(0, 0, 0);            GL11.glVertex3d(0, 10, 0);            GL11.glEnd();            GL11.glBegin(GL11.GL_LINES);            GL11.glColor3f(0.0f, 0.0f, 1.0f);            GL11.glVertex3d(0, 0, 0);            GL11.glVertex3d(0, 0, -10);            GL11.glEnd();        }        public void finishedPainting()        {            System.out.println("here");            GL11.glMatrixMode(GL11.GL_PROJECTION);            GL11.glLoadIdentity();            GL11.glOrtho(-13, 13, -1, 10, -30, 100);            GL11.glMatrixMode(GL11.GL_MODELVIEW);            GL11.glLoadIdentity();            GL11.glRotatef(35.264f, 1.0f, 0.0f, 0.0f);            GL11.glRotatef(-45.0f, 0.0f, 1.0f, 0.0f);            GL11.glScalef(1.0f, 1.0f, -1.0f);            GL11.glTranslatef( 0, 0, 0 );            GL11.glBegin(GL11.GL_LINES);            GL11.glColor3f(1.0f, 0.0f, 0.0f);            GL11.glVertex3d(0, 0, 0);            GL11.glVertex3d(10, 0, 0);            GL11.glEnd();            GL11.glBegin(GL11.GL_LINES);            GL11.glColor3f(0.0f, 1.0f, 0.0f);            GL11.glVertex3d(0, 0, 0);            GL11.glVertex3d(0, 10, 0);            GL11.glEnd();            GL11.glBegin(GL11.GL_LINES);            GL11.glColor3f(0.0f, 0.0f, 1.0f);            GL11.glVertex3d(0, 0, 0);            GL11.glVertex3d(0, 0, -10);            GL11.glEnd();        }}`

10
##### Support / Re: Isometric 3D in JPanel
« on: January 12, 2012, 09:44:22 am »
Added the IPaintListener. Now the canvas is simply black. I think that the code in the startPainting method isn't called at all since i placed some text to be printed to the console there, and nothing is being printed.

11
##### Support / Re: Isometric 3D in JPanel
« on: January 12, 2012, 09:38:20 am »
I've tried putting the opengl code in the startPainting() method, but there's no effect. I also put it in finishedPainting() but that didn't work. Am I missing something crucial?

Code: [Select]
`package orthogonal_test;import com.threed.jpct.*;import org.lwjgl.opengl.GL11;import javax.swing.*;import java.awt.*;/** * A simple HelloWorld using the OpenGL-renderer. * @author EgonOlsen * */public class Main implements IPaintListener { private World world; private FrameBuffer buffer; private Object3D box;        private Camera cam; public static void main(String[] args) throws Exception { new Main().loop(); } public Main() throws Exception { world = new World(); world.setAmbientLight(0, 255, 0); box = Primitives.getBox(1f, 1f); box.build(); world.addObject(box);                float dist = 30f;                cam = world.getCamera();                cam.setPosition( new SimpleVector( dist, dist, dist ) );                cam.lookAt( box.getTransformedCenter() ); } private void loop() throws Exception { buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL); buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE); buffer.enableRenderer(IRenderer.RENDERER_OPENGL, IRenderer.MODE_OPENGL);                buffer.setPaintListener(this);                JFrame frame = new JFrame();                frame.setSize( 800, 600 );                frame.setResizable(false);                Canvas canvas = buffer.enableGLCanvasRenderer();                frame.add(canvas);                frame.setVisible(true);                frame.setDefaultCloseOperation( JFrame.HIDE_ON_CLOSE );                while ( frame.isVisible() ) { buffer.clear(java.awt.Color.BLACK); world.renderScene(buffer); world.draw(buffer); buffer.update(); buffer.displayGLOnly(); Thread.sleep(10); } buffer.disableRenderer(IRenderer.RENDERER_OPENGL); buffer.dispose(); System.exit(0); }        public void startPainting()        {            GL11.glMatrixMode(GL11.GL_PROJECTION);            GL11.glLoadIdentity();            GL11.glOrtho(-13, 13, -1, 10, -30, 100);            GL11.glMatrixMode(GL11.GL_MODELVIEW);            GL11.glLoadIdentity();            GL11.glRotatef(35.264f, 1.0f, 0.0f, 0.0f);            GL11.glRotatef(-45.0f, 0.0f, 1.0f, 0.0f);            GL11.glScalef(1.0f, 1.0f, -1.0f);            GL11.glTranslatef( 0, 0, 0 );            GL11.glBegin(GL11.GL_LINES);            GL11.glColor3f(1.0f, 0.0f, 0.0f);            GL11.glVertex3d(0, 0, 0);            GL11.glVertex3d(10, 0, 0);            GL11.glEnd();            GL11.glBegin(GL11.GL_LINES);            GL11.glColor3f(0.0f, 1.0f, 0.0f);            GL11.glVertex3d(0, 0, 0);            GL11.glVertex3d(0, 10, 0);            GL11.glEnd();            GL11.glBegin(GL11.GL_LINES);            GL11.glColor3f(0.0f, 0.0f, 1.0f);            GL11.glVertex3d(0, 0, 0);            GL11.glVertex3d(0, 0, -10);            GL11.glEnd();        }        public void finishedPainting()        {           GL11.glMatrixMode(GL11.GL_PROJECTION);            GL11.glLoadIdentity();            float scalar = 50f;            //GL11.glOrtho(-13, 13, -1, 10, -30, 100);            GL11.glMatrixMode(GL11.GL_MODELVIEW);            GL11.glLoadIdentity();            GL11.glRotatef(35.264f, 1.0f, 0.0f, 0.0f);            GL11.glRotatef(-45.0f, 0.0f, 1.0f, 0.0f);            GL11.glScalef(1.0f, 1.0f, -1.0f);            GL11.glTranslatef( 0, 0, 0 );            GL11.glBegin(GL11.GL_LINES);            GL11.glColor3f(1.0f, 0.0f, 0.0f);            GL11.glVertex3d(0, 0, 0);            GL11.glVertex3d(10, 0, 0);            GL11.glEnd();            GL11.glBegin(GL11.GL_LINES);            GL11.glColor3f(0.0f, 1.0f, 0.0f);            GL11.glVertex3d(0, 0, 0);            GL11.glVertex3d(0, 10, 0);            GL11.glEnd();            GL11.glBegin(GL11.GL_LINES);            GL11.glColor3f(0.0f, 0.0f, 1.0f);            GL11.glVertex3d(0, 0, 0);            GL11.glVertex3d(0, 0, -10);            GL11.glEnd();        }}`

12
##### Support / Isometric 3D in JPanel
« on: January 12, 2012, 01:03:43 am »
Hi

I've got (I think) isometric 3D working, which is pretty nice. However, when I try to put it into a JPanel I get an error like this:

Code: [Select]
`Exception in thread "main" java.lang.NullPointerException        at org.lwjgl.opengl.GL11.glMatrixMode(GL11.java:2052)        at orthogonal_test.Main.loop(Main.java:56)        at orthogonal_test.Main.main(Main.java:22)`
And here's all the code:

Code: [Select]
`package orthogonal_test;import com.threed.jpct.*;import org.lwjgl.opengl.GL11;import javax.swing.*;import java.awt.*;/** * A simple HelloWorld using the OpenGL-renderer. * @author EgonOlsen * */public class Main { private World world; private FrameBuffer buffer; private Object3D box;        private Camera cam; public static void main(String[] args) throws Exception { new Main().loop(); } public Main() throws Exception { world = new World(); world.setAmbientLight(0, 255, 0); box = Primitives.getBox(1f, 1f); box.build(); world.addObject(box);                float dist = 30f;                cam = world.getCamera();                cam.setPosition( new SimpleVector( dist, dist, dist ) );                cam.lookAt( new SimpleVector( 0, 0, 0 ) ); } private void loop() throws Exception { buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL); buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE); buffer.enableRenderer(IRenderer.RENDERER_OPENGL);                JFrame frame = new JFrame();                Canvas canvas = buffer.enableGLCanvasRenderer();                frame.add(canvas);                frame.setVisible(true);                frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );                while ( frame.isVisible() ) { buffer.clear(java.awt.Color.BLACK); world.renderScene(buffer); world.drawWireframe(buffer, java.awt.Color.YELLOW); buffer.update();                                                GL11.glMatrixMode(GL11.GL_PROJECTION);                        GL11.glLoadIdentity();                        float scalar = 50f;                        //GL11.glOrtho(-13, 13, -1, 10, -30, 100);                        GL11.glMatrixMode(GL11.GL_MODELVIEW);                        GL11.glLoadIdentity();                        GL11.glRotatef(35.264f, 1.0f, 0.0f, 0.0f);                        GL11.glRotatef(-45.0f, 0.0f, 1.0f, 0.0f);                        GL11.glScalef(1.0f, 1.0f, -1.0f);                        GL11.glTranslatef( 0, 0, 0 );                                                GL11.glBegin(GL11.GL_LINES);                        GL11.glColor3f(1.0f, 0.0f, 0.0f);                        GL11.glVertex3d(0, 0, 0);                        GL11.glVertex3d(10, 0, 0);                        GL11.glEnd();                        GL11.glBegin(GL11.GL_LINES);                        GL11.glColor3f(0.0f, 1.0f, 0.0f);                        GL11.glVertex3d(0, 0, 0);                        GL11.glVertex3d(0, 10, 0);                        GL11.glEnd();                        GL11.glBegin(GL11.GL_LINES);                        GL11.glColor3f(0.0f, 0.0f, 1.0f);                        GL11.glVertex3d(0, 0, 0);                        GL11.glVertex3d(0, 0, -10);                        GL11.glEnd(); buffer.displayGLOnly(); Thread.sleep(10); } buffer.disableRenderer(IRenderer.RENDERER_OPENGL); buffer.dispose(); System.exit(0); }}`
Any help / code snippets would be greatly appreciated.

13
##### Support / Re: Orientating a car object to face a point
« on: November 24, 2011, 06:48:23 pm »
That seemed to do the trick. Thanks for your help - again!

14
##### Support / Re: Orientating a car object to face a point
« on: November 23, 2011, 08:43:12 pm »
Hm. I've made the changes you suggested, and the cone does indeed seem to orientate to the points now. However, it seems to orientate its base with the direction of the vector, if you know what I mean. I need the actual mesh to face the point "point on", so I tried using rotateMesh() on the cone after setting the rotation matrix. Needless to say, it didn't work; it just doesn't aim at the point. Any thoughts?

Code: [Select]
`SimpleVector directionVector = new SimpleVector(                            picked.centre.x - pointy.getTransformedCenter().x,                            picked.centre.y - pointy.getTransformedCenter().y,                            picked.centre.z - pointy.getTransformedCenter().z );                    Matrix rotationMatrix = directionVector.getRotationMatrix();                    pointy.setRotationMatrix(rotationMatrix);                    pointy.rotateMesh();`
I should have mentioned that picked is derived from a class that holds a SimpleVector as an attribute called centre; getting centre retrieves the SimpleVector.

15
##### Support / Re: Orientating a car object to face a point
« on: November 23, 2011, 03:36:52 pm »
Regarding step 1:

I have a cone (called pointy) and a point to aim it at, called picked, which is just a SimpleVector from an array called nodes. I then use this code to find the direction vector:

Code: [Select]
`picked = nodes[i];                    SimpleVector directionVector = new SimpleVector(                            picked.centre.x - pointy.getCenter().x,                            picked.centre.y - pointy.getCenter().y,                            picked.centre.z - pointy.getCenter().z );                    directionVector.add(                            new SimpleVector(                            pointy.getCenter().x,                            pointy.getCenter().y,                            pointy.getCenter().z )                            );`
Regarding steps 2 and 3:

I then get the rotation matrix from the rotation vector and apply this to the cone pointy.

Code: [Select]
`                    Matrix rotationMatrix = directionVector.getRotationMatrix();                    pointy.setRotationMatrix(rotationMatrix);`
However, pointy doesn't seem to face the direction vector. It seems to rotate a bit on one of its axes; the pointy bit of the cone does not face the point. So maybe I need to do some kind of transformation to make it rotate properly?

Pages: [1] 2