Jump to content
  • Advertisement

Colby_

Member
  • Content Count

    7
  • Joined

  • Last visited

Community Reputation

100 Neutral

About Colby_

  • Rank
    Newbie
  1. Colby_

    "Picking" with the mouse

    Looking from that tutorial, I was able to convert the C code to Java. However, it returns things such as 0, NaN, or sometimes insane coordinates, even if the point is on top of a rendered polygon. Am I missing a step? float[] screenToWorld(int x, int y) { IntBuffer viewport = ByteBuffer.allocateDirect(16 * 4).asIntBuffer(); FloatBuffer modelview = ByteBuffer.allocateDirect(16 * 4).asFloatBuffer(); FloatBuffer projection = ByteBuffer.allocateDirect(16 * 4).asFloatBuffer(); float winX, winY; glGetFloat(GL_MODELVIEW_MATRIX, modelview); glGetFloat(GL_PROJECTION_MATRIX, projection); glGetInteger(GL_VIEWPORT, viewport); winX = (float) x; winY = (float) viewport.get(3) - (float) y; FloatBuffer winZ = ByteBuffer.allocateDirect(1 * 4).asFloatBuffer(); glReadPixels(x, (int) winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, winZ); FloatBuffer pos = ByteBuffer.allocateDirect(3 * 4).asFloatBuffer(); gluUnProject(winX, winY, winZ.get(0), modelview, projection, viewport, pos); float[] raw = new float[3]; pos.get(raw); return raw; }
  2. Colby_

    "Picking" with the mouse

    I've seen that also, but I dont quite understand the parameters
  3. I've read tutorials on this, but I can't seem to get it to work. I don't think I understand what exactly is going on at all. What I'm trying to do is get the number of objects (and later the actual objects) that are intersected by a ray cast from the center of the screen. (Or where the mouse is) Heres what I have to so far, and it's printing -1 always. glLoadIdentity(); glRotatef(pit, 1.0f, 0.0f, 0.0f); glRotatef(yaw, 0.0f, 1.0f, 0.0f); glTranslatef(-x, -y, -z); glRenderMode(GL_SELECT); IntBuffer i = ByteBuffer.allocateDirect(64).asIntBuffer(); glGetInteger(GL_VIEWPORT, i); gluPickMatrix(canv.getWidth() / 2, canv.getHeight() / 2, 1.0f, 1.0f, i); gluPerspective(60f, 1.0f, 0.0001f, 1000.0f); world.draw(); int hits = glRenderMode(GL_RENDER); System.out.println(hits); glLoadIdentity(); glRotatef(pit, 1.0f, 0.0f, 0.0f); glRotatef(yaw, 0.0f, 1.0f, 0.0f); glTranslatef(-x, -y, -z); world.draw();
  4. Imagine I have a list of things I want to draw, and their exact positions in relation to the origin. For drawing the first object, I can simply translate to the coordinates of the object and draw it. However, for any object after that one, the points i enter are relative to the last translation. How can I reset similarly to glLoadIdentity(); but without discarding my camera rotations? Surely I dont have to subtract the coordinates of all models or re translate the camera for each position? For example, say I have two cubes at (0, 5, 0) and (0, 10, 0). I currently must draw them as so: translatecam translate(0, 5, 0); drawcube translate(0, 5, 0); drawcube updatescreen and I need to be able to do it like so: translatecam setresetpoint translate(0, 5, 0); drawcube reset translate(0, 10, 0); drawcube updatescreen
  5. Colby_

    Help with FPS camera?

    Thanks man i got it with the following code: (For anyone else needing it) if (Keyboard.isKeyDown(Keyboard.KEY_A)) { float yRotRad = (float) Math.toRadians(yaw); x += -0.04f * Math.cos(yRotRad); z += -0.04f * Math.sin(yRotRad); } if (Keyboard.isKeyDown(Keyboard.KEY_D)) { float yRotRad = (float) Math.toRadians(yaw); x += 0.04f * Math.cos(yRotRad); z += 0.04f * Math.sin(yRotRad); } if (Keyboard.isKeyDown(Keyboard.KEY_W)) { float pitchFactor = (float) Math.cos(Math.toRadians(pit)); x += (0.04F * (Math.sin(Math.sin(Math.toRadians(yaw))))) * pitchFactor; y += 0.04F * (Math.sin(Math.toRadians(pit))) * -1.0f; float yawFactor = (float) (Math.cos(Math.toRadians(pit))); z += (0.04 * (Math.cos(Math.toRadians(yaw))) * -1.0f) * yawFactor; } if (Keyboard.isKeyDown(Keyboard.KEY_S)) { float pitchFactor = (float) Math.cos(Math.toRadians(pit)); x -= (0.04F * (Math.sin(Math.sin(Math.toRadians(yaw))))) * pitchFactor; y -= 0.04F * (Math.sin(Math.toRadians(pit))) * -1.0f; float yawFactor = (float) (Math.cos(Math.toRadians(pit))); z -= (0.04 * (Math.cos(Math.toRadians(yaw))) * -1.0f) * yawFactor; }
  6. Colby_

    Help with FPS camera?

    Thanks but I honestly don't understand what you're telling me about the math.
  7. I've followed tutorials on how to do this to the letter, but I can't seem to get it to move around correctly. For example, W should go forward, and forward is defined by which direction the camera is pointing. Heres the main loop: float x = 0, y = 0, z = 0, pit = 0, yaw = 0; int size = 1; do { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { Display.destroy(); System.exit(0); } if (Keyboard.isKeyDown(Keyboard.KEY_A)) { x -= 0.04 * (float) Math.sin(Math.toRadians(yaw - 90)); z += 0.04 * (float) Math.cos(Math.toRadians(yaw - 90)); } if (Keyboard.isKeyDown(Keyboard.KEY_D)) { x -= 0.04 * (float) Math.sin(Math.toRadians(yaw + 90)); z += 0.04 * (float) Math.cos(Math.toRadians(yaw + 90)); } if (Keyboard.isKeyDown(Keyboard.KEY_W)) { x -= 0.04 * (float) Math.sin(Math.toRadians(yaw)); z += 0.04 * (float) Math.cos(Math.toRadians(yaw)); } if (Keyboard.isKeyDown(Keyboard.KEY_S)) { x += 0.04 * (float) Math.sin(Math.toRadians(yaw)); z -= 0.04 * (float) Math.cos(Math.toRadians(yaw)); } yaw += Mouse.getDX(); pit += Mouse.getDY(); Mouse.setGrabbed(true); glLoadIdentity(); GL11.glRotatef(pit / 3, 1.0f, 0.0f, 0.0f); GL11.glRotatef(yaw / 3, 0.0f, 1.0f, 0.0f); glTranslatef(x, y, z); //Some test world data drawCube(size, crate); glTranslatef(0.0f, 0.0f, -2.0f); drawCube(size, crate); glTranslatef(0.0f, 0.0f, -2.0f); drawCube(size, crate); glTranslatef(0.0f, 0.0f, -2.0f); drawCube(size, crate); glTranslatef(0.0f, 0.0f, -2.0f); drawCube(size, crate); glTranslatef(0.0f, 0.0f, -2.0f); drawCube(size, crate); glTranslatef(0.0f, 0.0f, -2.0f); drawCube(size, crate); Display.update(); } while (true);
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!