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.
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 MenuSimpleVector crossProduct = new SimpleVector( this.calcCross(otherNode) );
SimpleVector directionVector = new SimpleVector(
crossProduct.x - this.x,
crossProduct.y - this.y,
crossProduct.z - this.z );
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();
}
}
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();
}
}
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)
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);
}
}
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();
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 )
);
Matrix rotationMatrix = directionVector.getRotationMatrix();
pointy.setRotationMatrix(rotationMatrix);
Page created in 0.020 seconds with 12 queries.