Jump to content
  • Advertisement

robee00

Member
  • Content Count

    29
  • Joined

  • Last visited

Everything posted by robee00

  1. Hi!   What kind of shape should I use in a 2D topdown space game for collision? I was thinking about AABB, but as the ships are rotating they are not the best option. I was thinking about OBBs or a group of Bounding Circles. I'm more into the circles because of the performance, and I can define a ship's collider more precisely with more circles. I would like to hear your opinion too
  2. Hi   I wrote a simple OBJ loader but the texcoords are messed up somehow. I can't figure out what is wrong. I tried flipping the texture on the Y-Axis, no success. (Here is how my object looks like: http://imgur.com/d8edSyw   Code: (FaceData holds the IDs for vertices, normals and texcoords, Vertex class holds the data) public void parseObj(String path) { try { BufferedReader reader = new BufferedReader(new FileReader(new File("").getAbsolutePath() + "/res/" + path)); String line = reader.readLine(); while(line != null) { if(line.startsWith("v ")) { int start = line.indexOf(" "); String sub = line.substring(start + 1); String[] vertexStr = sub.split(" " ); pos.add(new Vector3f(Float.parseFloat(vertexStr[0]), Float.parseFloat(vertexStr[1]), Float.parseFloat(vertexStr[2]))); } if(line.startsWith("vt ")) { int start = line.indexOf(" "); String sub = line.substring(start + 1); String[] vertexStr = sub.split(" " ); tex.add(new Vector2f(Float.parseFloat(vertexStr[0]), Float.parseFloat(vertexStr[1]))); } if(line.startsWith("vn ")) { int start = line.indexOf(" "); String sub = line.substring(start + 1); String[] vertexStr = sub.split(" " ); norm.add(new Vector3f(Float.parseFloat(vertexStr[0]), Float.parseFloat(vertexStr[1]), Float.parseFloat(vertexStr[2]))); } if(line.startsWith("f ")) { int start = line.indexOf(" "); String sub = line.substring(start + 1); String[] vertexStr = sub.split(" "); for(int i = 0; i < vertexStr.length; i++) { String verStr = vertexStr[i].replaceAll("//", "/0/"); String[] asd = verStr.split("/"); FaceData data = new FaceData(); data.vertexID = Integer.parseInt(asd[0]); data.texID = Integer.parseInt(asd[1]); data.normalID = Integer.parseInt(asd[2]); faces.add(data); } } line = reader.readLine(); } reader.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } for(int i = 0; i < faces.size(); i++) { Vertex v = new Vertex(); v.pos = pos.get(faces.get(i).vertexID - 1); if(faces.get(i).texID != 0) { Vector2f t = new Vector2f(); t = tex.get(faces.get(i).texID - 1); t.y = t.y; v.texCoord.set(t); } else v.texCoord = new Vector2f(0,0); v.normal = norm.get(faces.get(i).normalID - 1); vertices.add(v); } }
  3. robee00

    OBJ loader for opengl (LWJGL)

    Ooops that t.y = t.y stayed in the code, I wrote t.y = 1f - t.y to flip the image on the y-axis. The texID's value is 0 by default, so I can check if there is no tex coords for that vertex.   https://mega.co.nz/#!8FtkXDzZ!R6S_71KMoKIhS4edYjq1VnnimMZ7TvLDL6OSmW_Zxuk <- link for obj and texture   It is not a cube, it's a sh*tty hallway, just made something to try the loader. Here is how it looks like http://i.imgur.com/sWXw7Lp.png   http://pastebin.com/38ECG3ge <- code for the class
  4. Hello guys.   I came across a problem today. I exported a single cube from blender, and I tried to wrote a simple .obj loader to use. I think my parsing method is okay, but I have problem putting the data into a vbo/ibo. The vertex and fragment shader is working, I used them before. What I get is a deformated cube. Like faces (quad) only got one of the tris drawn.   Vertex class contains fields for position, texcoords, and normals   FaceData just holds the ID for vertex, texcoord and normal. public class Model { ArrayList<Vertex> vertices = new ArrayList<Vertex>(); ArrayList<Vector3f> pos = new ArrayList<Vector3f>(); ArrayList<Vector2f> tex = new ArrayList<Vector2f>(); ArrayList<Vector3f> norm = new ArrayList<Vector3f>(); ArrayList<FaceData> faces = new ArrayList<FaceData>(); int vbo; int ibo; public int indexCount; public Model(String name) { parseObj(name); FloatBuffer vertBuffer = BufferUtils.createFloatBuffer(vertices.size() * 8); for(Vertex v : vertices) { vertBuffer.put(v.getElements()); } vertBuffer.flip(); vbo = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertBuffer, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); IntBuffer indices = BufferUtils.createIntBuffer(faces.size()); for(FaceData f : faces) { indices.put(f.vertexID - 1); indexCount++; } indices.flip(); ibo = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); } public void render() { GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); GL20.glEnableVertexAttribArray(0); GL20.glEnableVertexAttribArray(1); GL20.glEnableVertexAttribArray(2); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo); GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 32, 0); GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 32, 12); GL20.glVertexAttribPointer(2, 3, GL11.GL_FLOAT, false, 32, 20); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo); GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(1); GL20.glDisableVertexAttribArray(2); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); } public void parseObj(String path) { try { BufferedReader reader = new BufferedReader(new FileReader(new File("").getAbsolutePath() + "/res/" + path)); String line = reader.readLine(); while(line != null) { if(line.startsWith("v ")) { int start = line.indexOf(" "); String sub = line.substring(start + 1); String[] vertexStr = sub.split(" " ); pos.add(new Vector3f(Float.parseFloat(vertexStr[0]), Float.parseFloat(vertexStr[1]), Float.parseFloat(vertexStr[2]))); } if(line.startsWith("vt ")) { int start = line.indexOf(" "); String sub = line.substring(start + 1); String[] vertexStr = sub.split(" " ); tex.add(new Vector2f(Float.parseFloat(vertexStr[0]), Float.parseFloat(vertexStr[1]))); } if(line.startsWith("vn ")) { int start = line.indexOf(" "); String sub = line.substring(start + 1); String[] vertexStr = sub.split(" " ); norm.add(new Vector3f(Float.parseFloat(vertexStr[0]), Float.parseFloat(vertexStr[1]), Float.parseFloat(vertexStr[2]))); } if(line.startsWith("f ")) { int start = line.indexOf(" "); String sub = line.substring(start + 1); String[] vertexStr = sub.split(" "); for(int i = 0; i < vertexStr.length; i++) { String[] verStr = vertexStr[i].split("/"); FaceData data = new FaceData(); data.vertexID = Integer.parseInt(verStr[0]); //data.texID = Integer.parseInt(verStr[1]); data.normalID = Integer.parseInt(verStr[2]); faces.add(data); } } line = reader.readLine(); } reader.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } for(int i = 0; i < faces.size(); i++) { Vertex v = new Vertex(); v.pos = pos.get(faces.get(i).vertexID - 1); v.texCoord = new Vector2f(0,0); v.normal = norm.get(faces.get(i).normalID - 1); vertices.add(v); } } }
  5. robee00

    Loading OBJ model to VBO

    I replaced drawElement with drawArrays, and it draws the cube perfectly, so the problem is with the indices.
  6. Hi!   I'm having a plan on doing a 3D first person dungeon crawler. I'm doing the prototype with fantasy items (sword, cave setting, etc..), but I'm a sci-fi fan. I love game that is sci-fi. So, I was thinking about putting the game into sci-fi setting. But I'm having a hard time about melee weapons. Lightsabers are out, of course :P Energy swords? Or staffs? With ranged weapons, it's ok. I can drop in some guns, or something. And with enemies? Robots, aliens? And I'm not sure even if the dungeon crawler genre fits the scifi theme
  7. robee00

    2D top down RPG map design

    Hi!   I'm creating some little art for my game, and I don't know how should I make the walls...   I uploaded a pic which shows the 2 method, and I can't decide which one looks better in a game. I would go with 2, but it looks like if there was no wall there. I thought about dropping a shadowed, darker piece of wall instead of that "lines"
  8. Hi!   I'm currently learning modern OpenGL with LWJGL, and I have some experience in Java and C# (2 - 2,5 years). On the other hand, I want to learn C++ too. Is it "hard" to learn both? (C++ and OpenGL too) I have a bit of experience in C++, but I like the managed languages more. But I want to have some more experience in C++ too
  9. robee00

    Learning C++ with OpenGL

    That's why I ask it. I could learn OGL in a more familiar language than C++, but if I start learning C++ I could continue my OGL learning. So I could learn both of them
  10. Hello!   For now, I used OGL in fixed function mode. But now I want to learn the programmable pipeline now.   I tried to implement a simple diffuse - specular lighting shader from http://www.lighthouse3d.com/tutorials/glsl-core-tutorial/directional-lights-per-pixel/ . But I got wierd results (picture attached)   I uploaded my code to pastebin:   - Rendering: http://pastebin.com/cUDtHcWJ   - Vertex shader: http://pastebin.com/hE8s3KE7   - Fragment shader: http://pastebin.com/pVpr6zhR   And if I move my camera further the object, it gets brighter. Something I had to do with the position right?
  11. Okay, so I reduced it to render just one plane. And I found an other tutorial: http://www.rastertek.com/gl40tut06.html   I use EXACTLY the same shaders, and I use exactly the same position, and normals. But I got a black triangle instead of a yellow one. Looks like intensity is always zero.   The class of what I'm rendering: http://pastebin.com/ez5K9vN3
  12. Oops, I forgot to add that I left out the top and bottom sides. But okay, I'll try to rewrite that, and include the top and bottom sides
  13. robee00

    Sci fi dungeon crawler?

    Ooooo, thank you! That truly gave me some inspiration! Woah... :)
  14. robee00

    Check if enemy can see player

    I did it, I used the distance method that shazem given. I get the object with the smallest distance that collided with the ray. If it's the player's AABB, then gotcha, the enemy can see the player.
  15. Hello!   I encountered some problem with ray collision.   I want to detect if enemy can see the player. I cast a ray from the enemy's position in the direction of the player. If the first thing that the ray hits is the player, then the enemy can see the player. I store all of the AABB's in an ArrayList(no optimizations yet, just trying to solve it, no oct-tree, nothing :P). The problem is that I check if the ray hit any object with a foreach. So, even if the enemy can see the player, the method return false, because it hit a wall first in the terms of the list. Should I sort the list somehow? Smaller X positions first, then sort by Z?   Thanks in advance!   Cheers, R
  16. robee00

    AABB collision problem

    Thank you! I had to multiply with the -dist instead of the dot product. With the dot product I always went into the wall as seen on the picture. :/
  17. robee00

    AABB collision problem

    Hello!   I have some problems with AABB - AABB collision. I successfully get the normal of the face I hit, but when I'm trying to resolve the collision (I'm trying to get the sliding working) sometimes I go through the wall, sometimes only by a bit.    Here is the code, where I try to resolve the collision. if(BoundingBox.intersect(bb, Game.c2.bb)) { Vector3f reaction = new Vector3f(); reaction.x = bb.norm.x * - (Vector3f.dot(bb.norm, movement)); reaction.y = bb.norm.y * - (Vector3f.dot(bb.norm, movement)); reaction.z = bb.norm.z * - (Vector3f.dot(bb.norm, movement)); Vector3f.add(movement, reaction, movement); Vector3f.add(position, movement, position); bb.setVecMin(new Vector3f(position.x - BBSIZE, 0f, position.z - BBSIZE)); bb.setVecMax(new Vector3f(position.x + BBSIZE, 1f, position.z + BBSIZE)); } else { position.set(tempPos); bb.setVecMin(new Vector3f(position.x - BBSIZE, 0f, position.z - BBSIZE)); bb.setVecMax(new Vector3f(position.x + BBSIZE, 1f, position.z + BBSIZE)); }
  18. Hi! I'm currently have an idea about a game, but my problem is with my artist skills. I don't know whether I should make the game with placeholders, and recruit an artist to make the assets, while I finish the game, or simplify the characters that I can make graphics for it (like a character made of boxes, or I don't know)
  19. So awkward. I mistype a letter in the shader. I wrote gl_position instead of gl_Position
  20. Hi! I'm started to learn LWJGL and OpenGL, and following a tutorial, my code doesn't want to color the quad. Game.java: [source lang="java"]public class Game{ //VARIABLES private int vaoID = 0; private int vboID = 0; private int vboiID = 0; //for indices private int vbocID = 0; //for colors private int indicesCount = 0; private int vsID = 0; private int fsID = 0; private int pID = 0; public Game() { try { Display.setDisplayMode(new DisplayMode(1280,720)); Display.create(); } catch(LWJGLException e) { e.printStackTrace(); } } private void start() { init(); doMainLoop(); cleanUp(); } private void init() { //initialization GL11.glClearColor(0.4f, 0.6f, 0.9f, 0f); GL11.glViewport(0, 0, 1280, 720); //Default is counter-clockwise!!! //It's not important when using Elements! float[] vertices = { -0.5f,0.5f,0f,1f, -0.5f,-0.5f,0f,1f, 0.5f,-0.5f,0f,1f, 0.5f,0.5f,0f,1f }; //OGL Buffers requires flipped byte buffers FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(vertices.length); verticesBuffer.put(vertices); verticesBuffer.flip(); float[] colors = { 1f,0f,0f,1f, 0f,1f,0f,1f, 0f,0f,1f,1f, 1f,1f,1f,1f }; FloatBuffer colorBuffer = BufferUtils.createFloatBuffer(colors.length); colorBuffer.put(colors); colorBuffer.flip(); byte[] indices = { //Left bottom 0, 1, 2, //Right top 2, 3, 0 }; indicesCount = indices.length; ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount); indicesBuffer.put(indices); indicesBuffer.flip(); //Create new VAO, and bind the data // A VAO can have up to 16 attributes (VBO's) assigned to it by default vaoID = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vaoID); //Create new VBO, and bind // A VBO is a collection of Vectors which in this case resemble the location of each vertex. vboID = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_STATIC_DRAW); //Put the VBO in the attrib list at index 0 GL20.glVertexAttribPointer(0, 4 ,GL11.GL_FLOAT, false, 0, 0); //Deselect (bind to 0) the VBO GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); //Create new VBO for colors vbocID = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbocID); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, colorBuffer, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(1, 4, GL11.GL_FLOAT, false, 0, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); //Deselect (bind to 0) the VAO GL30.glBindVertexArray(0); //Create new VBO for indices, and bind it vboiID = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiID); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW); //Deselect it GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); //Load shaders vsID = loadShader("src/net/doubler/hexdef/basic.vs", GL20.GL_VERTEX_SHADER); fsID = loadShader("src/net/doubler/hexdef/basic.fs", GL20.GL_FRAGMENT_SHADER); //Create program, and apply shaders pID = GL20.glCreateProgram(); GL20.glAttachShader(pID, vsID); GL20.glAttachShader(pID, fsID); GL20.glLinkProgram(pID); //Position info will be attrib 0 GL20.glBindAttribLocation(pID, 0, "in_Position"); //Color info will be attrib 1 GL20.glBindAttribLocation(pID, 1, "in_Color"); //Validate program GL20.glValidateProgram(pID); } private void doMainLoop() { while(!Display.isCloseRequested()) { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GL20.glUseProgram(pID); //Bind to the VAO that has all the info about the quad vertices GL30.glBindVertexArray(vaoID); GL20.glEnableVertexAttribArray(0); GL20.glEnableVertexAttribArray(1); //Bind to the index VBO that has the info about the order GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiID); //Draw the vertices GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0); //Put everything back to default GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(1); GL30.glBindVertexArray(0); GL20.glUseProgram(0); Display.sync(60); Display.update(); } } private void cleanUp() { //clean up every trash //Delete shaders GL20.glUseProgram(0); GL20.glDetachShader(pID, vsID); GL20.glDetachShader(pID, fsID); GL20.glDeleteShader(vsID); GL20.glDeleteShader(fsID); GL20.glDeleteProgram(pID); //Select VAO GL30.glBindVertexArray(vaoID); //Disable the VBO index from the VAO attrib list GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(1); //Delete the vertex VBO GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL15.glDeleteBuffers(vboID); //Delete the index VBO GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL15.glDeleteBuffers(vboiID); //Delete the color VBO GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL15.glDeleteBuffers(vbocID); //Delete the VAO GL30.glBindVertexArray(0); GL30.glDeleteVertexArrays(vaoID); Display.destroy(); } public int loadShader(String name, int type) { StringBuilder source = new StringBuilder(); int shaderID = 0; try { BufferedReader reader = new BufferedReader(new FileReader(name)); String line; while((line = reader.readLine()) != null) { source.append(line).append("\n"); } reader.close(); } catch(IOException e) { e.printStackTrace(); System.exit(-1); } shaderID = GL20.glCreateShader(type); GL20.glShaderSource(shaderID, source); GL20.glCompileShader(shaderID); return shaderID; } public static void main(String[] args) { Game app = new Game(); app.start(); } }[/source] VertexShader: [source lang="cpp"]#version 330 in vec4 in_Position; in vec4 in_Color; out vec4 pass_Color; void main(void) { gl_Position = in_Position; pass_Color = in_Color; }[/source] FragmentShader: [source lang="cpp"]#version 330 in vec4 pass_Color; out vec4 out_Color; void main(void) { out_Color = pass_Color; }[/source] The only output I get is a white quad. It looks like the shaders are not compiling or I don't know. I tried to change out_Color to gl_FragColor, still white quad. Thanks in advance
  21. robee00

    Space game design

    Hi! I was recently thinking about a good game idea, and I finally find something appropriate for my goals. First, I think everybody knows Freelancer, right? Space game, with trading, fighting, and a lot of space ships. Now extends this game with some strategy element. Mining from planets, walking on planets(cities, of course), crafting. Addition to this, you have a space ship designer. Like in SPORE, but you can make bigger ships, like Millenium Falcon, Enterprise from Star Trek, and you can design how each area of the ship will take place. Mix in some story and some space fight, and ta-da. Here's my game idea. It's a kind of basic design, but I think it can be very interesting to make. It would be a single player game, but players could share their ships on the net. What's your opinion about this?
  22. Hi! I want my engine to use scripts, and I have a List<Script>. Each Script object holds information about a script: name, source code, etc. If I use CodeDomCompiler it will create a DLL. It's not bad as long as I don't want to recompile the script, but I want to edit those sources runtime, and then I cant recompile, because it cant overwrite the DLL. I thought about Lua and Python, but why use those, when I have C# here? Or can't I just compile them into the memory without creating any assembly? Or is there any way interpreting the scripts? (Searching on google gave no results for me) Thanks in advance
  23. robee00

    Scripting in C#/XNA

    That's ok, I tried them, using GenerateInMemory = true, but when I use the result (Assemby a = result.CompiledAssembly), then it throws an exception that it couldnt load the xxxxxx.dll. Edit: I don't know what I did, but now working. Interesting
  24. Hello! When developing my game, I ran into a problem: How can I properly check the mouse event for my UI? For example if I want to click on the map, then I dont want the game to handle that click, just only the UIHandler. Or closing a window, and in the game the left click is shooting, or casting a spell. Then if I want to close the window, my character shoots a fireball and closes the window. How can I solve this problem?
  • 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!