Note that there are some explanatory texts on larger screens.

plurals
  1. POGame Events run fine, but scene does not render
    primarykey
    data
    text
    <p>I am creating my own simple game engine for use in some of my upcoming projects. I have a world Object that stores a bunch of objects that extend a base class RenderObject.</p> <p>RenderObject contains things like scale rotation position smooth shading or not, etc. and forces all extending classes to implement their own method render().</p> <p>To navigate my world, I have an FPS style camera control setup, which I've tested via system.out.println() to check pitch and yaw and it's working correctly.</p> <p><strong>However none of my objects are rendering. My world objet has a method called renderObjects() which cycles through all the objects in the world and calls the render() function of them.</strong> <em>FIXED - New problem... Now I'm getting 4 2x2 pixel dots that randomly fly around, in a specific place. and then I move my mouse the entire cluster moves. Each game tick the onUpdate() method is called, and then lookThrough()</em></p> <p>FPSCameraControl.java</p> <pre><code>public class FPSCameraControl { private boolean DEBUG = false; public Vector3f position = null; public float yaw = 0.0f; public float pitch = 0.0f; public FPSCameraControl(float x, float y, float z) { position = new Vector3f(x, y, z); } public void yaw_(float amount) { yaw -= amount; if(yaw&gt;360){ yaw=0+(yaw-360); } if(yaw&lt;1){ yaw=360-(1-yaw); } } public void pitch_(float amount) { pitch -= amount; if(pitch&gt;=155) { pitch=155; } if(pitch&lt;=25) { pitch=25; } } public void walkForward(float distance) { position.x -= -distance * (float)Math.sin(Math.toRadians(yaw)); position.z += -distance * (float)Math.cos(Math.toRadians(yaw)); } public void walkBackwards(float distance) { position.x += -distance * (float)Math.sin(Math.toRadians(yaw)); position.z -= -distance * (float)Math.cos(Math.toRadians(yaw)); } public void strafeLeft(float distance) { position.x -= distance * (float)Math.sin(Math.toRadians(yaw-90)); position.z += distance * (float)Math.cos(Math.toRadians(yaw-90)); } public void strafeRight(float distance) { position.x -= distance * (float)Math.sin(Math.toRadians(yaw+90)); position.z += distance * (float)Math.cos(Math.toRadians(yaw+90)); } public void lookThrough() { GL11.glRotatef(pitch, 1.0f, 0.0f, 0.0f); GL11.glRotatef(yaw, 0.0f, 1.0f, 0.0f); GL11.glTranslatef(position.x, position.y, position.z); } public void onUpdate() { debug("Updating View"); //Calculate Sensitivity float sen = (0.02F*10); debug("Sensitivity: " + sen); //Get Center Of Screen int cx = Display.getDisplayMode().getWidth()/2; int cy = Display.getDisplayMode().getHeight()/2; //Get Mouse Position From Center int x = Mouse.getX()-cx; int y = Mouse.getY()-cy; debug("Mouse Moved: " + x + ", " + y); //Apply Inverting If Set //Apply Sensitivity float _yaw = (x*sen); float _pitch = (y*sen); yaw_(_yaw); pitch_(_pitch); debug("New Yaw: " + yaw); debug("New Pitch: " + pitch); UpdatePosition(); //SET MOUSE TO CENTER Mouse.setCursorPosition(cx, cy); lookThrough(); } public void printROT() { System.out.println("Pitch : "+pitch); System.out.println("Yaw : "+yaw); System.out.println(); System.out.println("XYZ : "+position.x+", "+position.y+", "+position.z); } public void debug(String msg) { if(DEBUG) { System.out.println(msg); } } public void UpdatePosition() { float f=0; float b=0; float r=0; float l=0; boolean moved =false; boolean shift = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT); if(Keyboard.isKeyDown(Keyboard.KEY_W)) { if(shift) { f=0.04F; } else { f=0.02F; } moved=true; } if(Keyboard.isKeyDown(Keyboard.KEY_S)) { if(shift) { b=0.04F; } else { b=0.02F; } moved=true; } if(Keyboard.isKeyDown(Keyboard.KEY_D)) { if(shift) { r=0.025F; } else { r=0.016F; } moved=true; } if(Keyboard.isKeyDown(Keyboard.KEY_A)) { if(shift) { l=0.02F; } else { l=0.016F; } moved=true; } if(moved) { walkForward(f); walkBackwards(b); strafeLeft(l); strafeRight(r); } } } </code></pre> <p>RenderObject.java</p> <pre><code>public abstract class RenderObject { public double [] location = new double [] {0, 0, 0}; public double [] rotation = new double [] {0, 0, 0}; public double [] scale = new double [] {1, 1, 1}; public Color color = new Color(180, 180, 180); public boolean smooth = false; public RenderObject parent = null; public LinkedList&lt;RenderObject&gt; children = new LinkedList&lt;RenderObject&gt;(); public abstract void render(); public void setScale(double x, double y, double z) { scale = new double[]{x, y, z}; } public void setParent(RenderObject object) { parent = object; } public void removeParent() { parent = null; } public RenderObject getParent() { return parent; } public void addChild(RenderObject object) { object.setParent(this); children.add(object); } public void removeChild(RenderObject object) { if(children.contains(object)) { object.removeParent(); children.remove(object); } } } </code></pre> <p>And RenderCube.java</p> <pre><code>public class RenderCube extends RenderObject { @Override public void render() { if(smooth) { GL11.glShadeModel(GL11.GL_SMOOTH); } else { GL11.glShadeModel(GL11.GL_FLAT); } GL11.glBegin(GL11.GL_QUADS); GL11.glPushMatrix(); GL11.glColor3b( color.getRedByte(),color.getGreenByte(), color.getBlueByte() ); GL11.glRotated(rotation[0], 1.0, 0.0, 0.0); GL11.glRotated(rotation[1], 0.0, 1.0, 0.0); GL11.glRotated(rotation[2], 0.0, 0.0, 1.0); //TOP GL11.glNormal3d(0.0, 1.0, 0.0); GL11.glVertex3d(location[0]-scale[0], location[1]+scale[1], location[2]-scale[2]); GL11.glVertex3d(location[0]-scale[0], location[1]+scale[1], location[2]+scale[2]); GL11.glVertex3d(location[0]+scale[0], location[1]+scale[1], location[2]+scale[2]); GL11.glVertex3d(location[0]+scale[0], location[1]+scale[1], location[2]-scale[2]); //BOTTOM GL11.glNormal3d(0.0, -1.0, 0.0); GL11.glVertex3d(location[0]-scale[0], location[1]-scale[1], location[2]-scale[2]); GL11.glVertex3d(location[0]-scale[0], location[1]-scale[1], location[2]+scale[2]); GL11.glVertex3d(location[0]+scale[0], location[1]-scale[1], location[2]+scale[2]); GL11.glVertex3d(location[0]+scale[0], location[1]-scale[1], location[2]-scale[2]); //FRONT GL11.glNormal3d(0.0, 0.0, 1.0); GL11.glVertex3d(location[0]-scale[0], location[1]+scale[1], location[2]+scale[2]); GL11.glVertex3d(location[0]+scale[0], location[1]+scale[1], location[2]+scale[2]); GL11.glVertex3d(location[0]+scale[0], location[1]-scale[1], location[2]+scale[2]); GL11.glVertex3d(location[0]-scale[0], location[1]-scale[1], location[2]+scale[2]); //BACK GL11.glNormal3d(0.0, 0.0, -1.0); GL11.glVertex3d(location[0]-scale[0], location[1]+scale[1], location[2]-scale[2]); GL11.glVertex3d(location[0]+scale[0], location[1]+scale[1], location[2]-scale[2]); GL11.glVertex3d(location[0]+scale[0], location[1]-scale[1], location[2]-scale[2]); GL11.glVertex3d(location[0]-scale[0], location[1]-scale[1], location[2]-scale[2]); //RIGHT GL11.glNormal3d(1.0, 0.0, 0.0); GL11.glVertex3d(location[0]+scale[0], location[1]+scale[1], location[2]+scale[2]); GL11.glVertex3d(location[0]+scale[0], location[1]+scale[1], location[2]-scale[2]); GL11.glVertex3d(location[0]+scale[0], location[1]-scale[1], location[2]-scale[2]); GL11.glVertex3d(location[0]+scale[0], location[1]-scale[1], location[2]+scale[2]); //LEFT GL11.glNormal3d(-1.0, 0.0, 0.0); GL11.glVertex3d(location[0]-scale[0], location[1]+scale[1], location[2]+scale[2]); GL11.glVertex3d(location[0]-scale[0], location[1]+scale[1], location[2]-scale[2]); GL11.glVertex3d(location[0]-scale[0], location[1]-scale[1], location[2]-scale[2]); GL11.glVertex3d(location[0]-scale[0], location[1]-scale[1], location[2]+scale[2]); Color _color = new Color(180, 180, 180); GL11.glColor3b( _color.getRedByte(),_color.getGreenByte(), _color.getBlueByte() ); GL11.glPopMatrix(); GL11.glEnd(); } } </code></pre> <p>Does anyone see what might not be working? Cause I don't.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload