Jump to content
  • Advertisement

Zaphyk

Member
  • Content Count

    26
  • Joined

  • Last visited

Everything posted by Zaphyk

  1. I am currently working on a dynamic LOD system, After searching for algorithms to do this I found the quadric mesh simplification which looked very promising, however I have no idea how to implement it without any clear example of code. Does anyone have an example of how to implement this algorithm or any mesh simplification algorithm which would be useful for my goal?
  2. I am developing my engine using the OpenGL 3.3 compatibility profile. It runs as expected on my NVIDIA card and on my Intel Card however when I tried it on an AMD setup it ran 3 times worse than on the other setups. Could this be a AMD driver thing or is this probably a problem with my OGL code? Could a different code standard create such bad performance?
  3. Hello, I tried implementing the GJK algorithm for convex collision detection by using this video and this page but my implementation doest work correctly, I assume there is something wrong around the 4th case (Tetrahedron), here is my code: private static Vector3 Support(List<Vector3> Vertices, Vector3 Direction){ float highest = float.MinValue; Vector3 support = Vector3.Zero; for (int i = 0; i < Vertices.Count; ++i) { Vector3 v = Vertices[i]; float dot = Vector3.Dot(Direction, v); if (dot > highest) { highest = dot; support = v; } } return support; } public static bool Collides(CollisionShape Shape1, CollisionShape Shape2){ Vector3 D = Vector3.UnitX; Vector3 S = Support(Shape1.Vertices, D) - Support(Shape2.Vertices,-D); List<Vector3> Points = new List<Vector3>(); Points.Add(S); D = -S; int Steps = 0; while(Steps < 50){ Vector3 A = Support(Shape1.Vertices, D) - Support(Shape2.Vertices,-D); Points.Add(A); if( Vector3.Dot(Points.Last(), D) < 0 ) return false; if( ContainsOrigin(Points, ref D) ) return true; Steps++; } return false; } private static Vector3 TripleProduct(Vector3 A, Vector3 B, Vector3 C){ return Vector3.Cross( Vector3.Cross(A,B), C ); } private static bool ContainsOrigin(List<Vector3> Array, ref Vector3 Direction){ if(Array.Count == 4) return Tetrahedron(Array, ref Direction); Vector3 A = Array.Last(); Vector3 AO = -A; if(Array.Count == 3){ Vector3 B = Array[1]; Vector3 C = Array[0]; Vector3 AB = B - A; Vector3 AC = C - A; Vector3 ABC = Vector3.Cross(AB, AC); if( Vector3.Dot(Vector3.Cross(ABC, AC), AO) > 0){ if(Vector3.Dot(AC, AO) > 0){ Array.Remove(B); Direction = TripleProduct(AC,AO,AC); }else{ if(Vector3.Dot(AB, AO) > 0){ Array.Remove(C); Direction = TripleProduct(AB,AO,AB); }else{ Array.Remove(B); Array.Remove(C); Direction = AO; } } }else{ if(Vector3.Dot( Vector3.Cross(ABC, AB), AO) > 0 ){ if(Vector3.Dot(AB, AO) > 0){ Array.Remove(C); Direction = TripleProduct(AB,AO,AB); }else{ Array.Remove(B); Array.Remove(C); Direction = AO; } }else{ if( Vector3.Dot(ABC, AO) > 0){ Direction = ABC; }else{ Vector3 C0 = Array[0]; Array[0] = Array[1]; Array[1] = C0; Direction -= ABC; } } } }else{ Vector3 B = Array[0]; Vector3 AB = B - A; if(Vector3.Dot(AB, AO) > 0) Direction = TripleProduct(AB, AO, AB); else Direction = AO; } return false; } private static bool Tetrahedron(List<Vector3> Array, ref Vector3 Direction){ Vector3 AO = -Array.Last(); Vector3 AB = Array[2] - Array.Last(); Vector3 AC = Array[1] - Array.Last(); Vector3 ABC = Vector3.Cross(AB, AC); //CASE 1 if (Vector3.Dot(AO, ABC) > 0) { CheckTetrahedron(Array, AO, AB, AC, ABC, Direction); } //CASE 2: Vector3 AD = Array.First() - Array.Last(); Vector3 ACD = Vector3.Cross(AC, AD); if (Vector3.Dot(ACD,AO) > 0) { //in front of triangle ACD Array[2] = Array[1]; Array[1] = Array[0]; AB = AC; AC = AD; ABC = ACD; CheckTetrahedron(Array, AO, AB, AC, ABC, Direction); } Vector3 ADB = Vector3.Cross(AD, AB); //same direaction with ao if (Vector3.Dot(ADB, AO) > 0) { //in front of triangle ADB Array[1] = Array[2]; Array[2] = Array[0]; AC = AB; AB = AD; ABC = ADB; CheckTetrahedron(Array, AO, AB, AC, ABC, Direction); } //origin in tetrahedron return true; } private static bool CheckTetrahedron(List<Vector3> Array, Vector3 AO, Vector3 AB, Vector3 AC, Vector3 ABC, Vector3 Direction) { Vector3 ab_abc = Vector3.Cross(AB, ABC); if (Vector3.Dot(AO, ab_abc) > 0) { Array.RemoveAt(0); Direction = Vector3.Cross(Vector3.Cross(AB, AO), AB); return false; } Vector3 acp = Vector3.Cross(ABC, AC); if (Vector3.Dot(AO,acp) > 0) { Array.RemoveAt(0); Direction = Vector3.Cross(Vector3.Cross(AC, AO), AC); return false; } Array.RemoveAt(Array.Count-1); Direction = ABC; return false; } Does anyone has a functional, comented 3d implementation I can take a look at or know where the problem is?   Thanks for the help.
  4. Zaphyk

    Problem with my GJK implementation

    It was a typo when I did the port. Thanks you very much for the code, it seems to be working amazingly well. :)
  5. Zaphyk

    Problem with my GJK implementation

    Oh thanks, I just ported your implementation and it works! But I have some collision it's not detecting, I would like to know if it is a problem with my port or if you had this issue in your implementaion.
  6. Zaphyk

    Problem with my GJK implementation

    Thanks man, this really helps, can you please send me the CShapeInstance class so I can check the GetSupport method?
  7. Zaphyk

    Problem with my GJK implementation

    Why do you think it wont be worth it?It would be too time consuming? Do you know of any other algorithm to achieve this? Also, do you recommend me to instead use a physics library like bullet? 
  8. Zaphyk

    Problem with my GJK implementation

    Interesting, out of curosity what would you use a GJK implementation for? Also do you have a SAT-GJK implementation for me to see?
  9. Zaphyk

    Problem with my GJK implementation

    Thanks for the resource, What advantage GJK gives you over SAT-GJK when detecting collision? Which one is faster? And which one in easier to implement?
  10. Hello, in the past few days i've been trying to implement Mouse Picking on my 3D game, however i am getting some strange results. Below is the code i am using. If anyone know any algorithm which works or can help me figure out why this doesnt work i will appreciate it very much. Vector4 world = new Vector4( (2 * mouse.X) / viewport.Width -1, -(2 * mouse.Y) / viewport.Height -1, -1, 1 Matrix4 invProj = Matrix4.Invert(proj); Vector4 eye = Vector4.Transform(world, invProj); world = new Vector4(eye.X, eye.Y, -1, 1); Matrix4 invView = Matrix4.Invert(view); Vector4 invVec = Vector4.Transform(world, invView); Vector3 raydirection = new Vector3(invVec.X, invVec.Y, invVec.Z).Normalized();
  11. Hello, I'm trying to create a skybox in OpenGL I managed to draw the cube and change its color but i am not able to bind the texture to the cubemap or to bind the cubemap into the skybox. Below is some of my code in C# (i am using a binding):   The CubeMap class public class CubeMap     {         public uint ID;         Image Source;                  public CubeMap(string source){                          Source = new Bitmap(source);                          List<Bitmap> Faces = new List<Bitmap>();             Bitmap NewBmp = new Bitmap(128,128);             using(Graphics G = Graphics.FromImage(NewBmp)){                                  G.DrawImage(Source,0,0, new Rectangle(384,128,128,128),GraphicsUnit.Pixel);                 Faces.Add((Bitmap) NewBmp.Clone());//right                                  G.DrawImage(Source,0,0, new Rectangle(0,128,128,128),GraphicsUnit.Pixel);                 Faces.Add((Bitmap) NewBmp.Clone());//left                                  G.DrawImage(Source,0,0, new Rectangle(0,0,128,128),GraphicsUnit.Pixel);                 Faces.Add((Bitmap) NewBmp.Clone());//top                                  G.DrawImage(Source,0,0, new Rectangle(0,256,128,128),GraphicsUnit.Pixel);                 Faces.Add((Bitmap) NewBmp.Clone());                                  G.DrawImage(Source,0,0, new Rectangle(512,128,128,128),GraphicsUnit.Pixel);                 Faces.Add((Bitmap) NewBmp.Clone());                                  G.DrawImage(Source,0,0, new Rectangle(128,128,128,128),GraphicsUnit.Pixel);                 Faces.Add((Bitmap) NewBmp.Clone());             }                          GL.GenTextures(1, out ID);             GL.ActiveTexture(TextureUnit.Texture0);             GL.BindTexture(TextureTarget.TextureCubeMap, ID);                          for(int i = 0; i<Faces.Count; i++){                 System.Drawing.Imaging.BitmapData data = Faces[i].LockBits(new Rectangle(0,0,Faces[i].Width, Faces[i].Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);                                  GL.TexImage2D(TextureTarget.TextureCubeMapPositiveX+i, 0, PixelInternalFormat.Rgb, data.Width, data.Height,0, PixelFormat.Rgb, PixelType.UnsignedByte, data.Scan0);                                  Faces[i].UnlockBits(data);             }                          GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);             GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);             GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (int) TextureWrapMode.ClampToEdge);             GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (int) TextureWrapMode.ClampToEdge);             GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapR, (int) TextureWrapMode.ClampToEdge);                          GL.BindTexture(TextureTarget.TextureCubeMap, 0);         } Here I bind the cubemap to the shader SkyboxShader.Bind(); GL.Uniform1(GL.GetUniformLocation(SkyboxShader.ShaderID, "skybox"), 0); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.TextureCubeMap, Box.ID);//Box is an object of type cubemap              GL.BindBuffer(BufferTarget.ArrayBuffer, BufferID);              GL.BindVertexArray(ArrayID); GL.EnableVertexAttribArray(0);              GL.DrawArrays(PrimitiveType.Triangles, 0, 36);              GL.BindVertexArray(0);              SkyboxShader.UnBind(); Vertex Shader #version 120 attribute vec3 position; varying vec3 TexCoords; void main() { gl_Position = vec4(position, 1.0); TexCoords = position; } Fragment Shader #version 120 varying vec3 TexCoords; uniform samplerCube skybox; void main() {     gl_FragColor = textureCube(skybox, TexCoords); } OpenGL did not throw any errors, and a black box is being rendered instead of the skybox.
  12. Zaphyk

    OpenGL Skybox

    It was a typo from rewriting my code here, I edited the post fixing the typo
  13. Zaphyk

    OpenGL Skybox

    Hello, I'm trying to create a skybox in OpenGL I managed to draw the cube and change its color but i am not able to bind the texture to the cubemap or to bind the cubemap into the skybox. Below is some of my code in C# (i am using a binding):   The CubeMap class public class CubeMap { public uint ID; Image Source; public CubeMap(string source){ Source = new Bitmap(source); List<Bitmap> Faces = new List<Bitmap>(); Bitmap NewBmp = new Bitmap(128,128); using(Graphics G = Graphics.FromImage(NewBmp)){ G.DrawImage(Source,0,0, new Rectangle(384,128,128,128),GraphicsUnit.Pixel); Faces.Add((Bitmap) NewBmp.Clone());//right G.DrawImage(Source,0,0, new Rectangle(0,128,128,128),GraphicsUnit.Pixel); Faces.Add((Bitmap) NewBmp.Clone());//left G.DrawImage(Source,0,0, new Rectangle(0,0,128,128),GraphicsUnit.Pixel); Faces.Add((Bitmap) NewBmp.Clone());//top G.DrawImage(Source,0,0, new Rectangle(0,256,128,128),GraphicsUnit.Pixel); Faces.Add((Bitmap) NewBmp.Clone()); G.DrawImage(Source,0,0, new Rectangle(512,128,128,128),GraphicsUnit.Pixel); Faces.Add((Bitmap) NewBmp.Clone()); G.DrawImage(Source,0,0, new Rectangle(128,128,128,128),GraphicsUnit.Pixel); Faces.Add((Bitmap) NewBmp.Clone()); } GL.GenTextures(1, out ID); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.TextureCubeMap, ID); for(int i = 0; i<Faces.Count; i++){ System.Drawing.Imaging.BitmapData data = Faces[i].LockBits(new Rectangle(0,0,Faces[i].Width, Faces[i].Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); GL.TexImage2D(TextureTarget.TextureCubeMapPositiveX+i, 0, PixelInternalFormat.Rgb, data.Width, data.Height,0, PixelFormat.Rgb, PixelType.UnsignedByte, data.Scan0); Faces[i].UnlockBits(data); } GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (int) TextureWrapMode.ClampToEdge); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (int) TextureWrapMode.ClampToEdge); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapR, (int) TextureWrapMode.ClampToEdge); GL.BindTexture(TextureTarget.TextureCubeMap, 0); } Here I bind the cubemap to the shader SkyboxShader.Bind(); GL.Uniform1(GL.GetUniformLocation(SkyboxShader.ShaderID, "skybox"), 0); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.TextureCubeMap, Box.ID);//Box is an object of type cubemap GL.BindBuffer(BufferTarget.ArrayBuffer, BufferID); GL.BindVertexArray(ArrayID); GL.EnableVertexAttribArray(0); GL.DrawArrays(PrimitiveType.Triangles, 0, 36); GL.BindVertexArray(0); SkyboxShader.UnBind(); Vertex Shader #version 120 attribute vec3 position; varying vec3 TexCoords; void main() { gl_Position = vec4(position, 1.0); TexCoords = position; } Fragment Shader #version 120 varying vec3 TexCoords; uniform samplerCube skybox; void main() { gl_FragColor = textureCube(skybox, TexCoords); } OpenGL did not throw any errors, and a black box is being rendered instead of the skybox.
  14. Zaphyk

    Voxel Shift

    Procedural world generation made in C# with OpenTK. This is not the official name for my game, if you have any game/name suggestion leave it in the comments
  15. From the album: Voxel Shift

    An nice implementation of fog which comes closer to the player depending on the daytime for my currently in development roguelike/adventure game, follow its development or ask me anything at [url="http://zaphyk.blogspot.com.ar"]http://zaphyk.blogspot.com.ar[/url]

    © Zaphyk

  16. Zaphyk

    Procedurally generated biome

    From the album: Voxel Shift

    This is some procedurally generated biome for my currently in development roguelike/adventure game, follow its development or ask me anything at [url="http://zaphyk.blogspot.com.ar"]http://zaphyk.blogspot.com.ar[/url]

    © Zaphyk

  17. Zaphyk

    Procedurally generated voxel clouds

    From the album: Voxel Shift

    These are some procedurally generated, highly effiecient voxel clouds created at runtime, they are for my roguelike/adventure game currently in development, follow its development or ask me anything at [url="http://zaphyk.blogspot.com.ar"]http://zaphyk.blogspot.com.ar[/url]

    © Zaphyk

  18. Hello, Can someone explain me the math behind Glu.Unproject, just to know how it works and to get better in math for 3d games, Thanks
  19. I am struggling to create an algorithm to remove the unseen triangles from the mesh of the chunk I tried by checking if the adyacent voxels are air. Here is some of my code for(int y=CHUNK_HEIGHT-1;y>0;y--){ for(int x=0;x<CHUNK_WIDTH;x++){ for(int z=0;z<CHUNK_WIDTH;z++){ if(!m_blocks[x,y,z].IsActive) continue; CubeData cube = new CubeData(CubeData.CreateCubeColor(m_blocks[x,y,z].GetColor(m_blocks[x,y,z].Type)),new OpenTK.Vector3(x+OffsetX, y, z+OffsetZ)); cube = CubeData.CutCubeFace(cube, CutFaceMode.ONLY, Face.ALL); bool yP = false, yN = false, xP = false, xN = false, zP = false, zN = false; if(x < CHUNK_WIDTH-1 && m_blocks[x+1,y,z].Type == BlockType.AIR) xP = true; if(x > 0 && m_blocks[x-1,y,z].Type == BlockType.AIR) xN = true; if(z < CHUNK_WIDTH-1 && m_blocks[x,y,z+1].Type == BlockType.AIR) zP = true; if(z > 0 && m_blocks[x,y,z-1].Type == BlockType.AIR) zN = true; if(y < CHUNK_HEIGHT-1 && m_blocks[x,y+1,z].Type == BlockType.AIR) yP = true; if(y > 0 && m_blocks[x,y-1,z].Type == BlockType.AIR) yN = true; if(xP) cube = CubeData.CutCubeFace(cube, CutFaceMode.ADD, Face.FRONT); if(xN) cube = CubeData.CutCubeFace(cube, CutFaceMode.ADD, Face.BACK); if(zN) cube = CubeData.CutCubeFace(cube, CutFaceMode.ADD, Face.LEFT); if(zP) cube = CubeData.CutCubeFace(cube, CutFaceMode.ADD, Face.RIGHT); if(yP) cube = CubeData.CutCubeFace(cube, CutFaceMode.ADD, Face.UP); if(yN) cube = CubeData.CutCubeFace(cube, CutFaceMode.ADD, Face.DOWN); if(cube.HasFaces()) Mesh.AddCube(cube); } } } However this lead to some weird effects when 2 air blocks are adyacent, below are some images. Those are air blocks separeted   As you can see when more air blocks are added just some faces appear incomplete or without sense.   Thank you for your time and If anyone can give me any advice or help i would appreciate it.   EDIT: I already solved it, but always remeber PREMATURE OPTIMIZATION IS THE ROOT OF ALL EVIL!!!!
  20. Tiles are 32x32 pixels, if i move the character by 32 pixels like in this piece of code the characters moves too roughly but if i move him by less pixels he can stay in middle of 2 tiles. Can someone give some pseudo code to orientate me? Thanks   int TILESIZE = 32; Input input = container.getInput(); if (input.isKeyDown(Input.KEY_W) && Y != 0) { Y -= Game.TILESIZE;// moves the sprite by 32 pixel up Movement.update(delta);//updates animation }else if (input.isKeyDown(Input.KEY_A) && X != 0) { X -= Game.TILESIZE; Movement.update(delta); }else if (input.isKeyDown(Input.KEY_D) && X != Game.MapLimitX) { X += Game.TILESIZE; Movement.update(delta); }else if (input.isKeyDown(Input.KEY_S) && Y != Game.MapLimitY) { Y += Game.TILESIZE; Movement.update(delta); }
  21. Zaphyk

    Smooth Tile movement.

    I tried your code and it has the same problem as the on i put above, the sprite can end in the middle of two tiles. If you want to review the adaption of the code you gave me i am gonna leave it here btw it is in Java.   public void processInput(GameContainer gc, int delta){ Input input = gc.getInput(); if (!MovingState.equals(State.IDLE)){ update_position(delta); return; } if (input.isKeyDown(Input.KEY_A) && X != 0){ MovingState = State.MOVING_LEFT; TargetX = X - Game.TILESIZE; update_position(delta); } if (input.isKeyDown(Input.KEY_D) && X != Game.MapLimitX){ MovingState = State.MOVING_RIGHT; TargetX = X + Game.TILESIZE; update_position(delta); } if (input.isKeyDown(Input.KEY_W) && Y != 0){ MovingState = State.MOVING_UP; TargetY = Y - Game.TILESIZE; update_position(delta); } if (input.isKeyDown(Input.KEY_S) && Y != Game.MapLimitY){ MovingState = State.MOVING_DOWN; TargetY = Y + Game.TILESIZE; update_position(delta); } System.out.println(MovingState.name()); } void update_position (int delta){ if (MovingState.equals(State.MOVING_LEFT)){ if (X == TargetX){ return; } newX = X - (int) (WALKSPEED * delta); if (newX <= TargetX){ newX = TargetX; MovingState = State.IDLE; } X = newX; }else if(MovingState.equals(State.MOVING_RIGHT)){ if (X == TargetX){ return; } newX = X + (int) (WALKSPEED * delta); if (newX >= TargetX){ newX = TargetX; MovingState = State.IDLE; } X = newX; }else if(MovingState.equals(State.MOVING_UP)){ if (Y == TargetY){ return; } newY = Y - (int) (WALKSPEED * delta); if (newY <= TargetY){ newY = TargetY; MovingState = State.IDLE; } Y = newY; } else if(MovingState.equals(State.MOVING_DOWN)){ if (Y == TargetY){ return; } newY = Y + (int) (WALKSPEED * delta); if (newY >= TargetY){ newY = TargetY; MovingState = State.IDLE; } Y = newY; } } Now i am gonna try Satharis solution because with glportal solution the chracter could end in the middle of a tile, thanks anyway.
  22.         I am quite experienced with Java, i made several bukkit plugins and a few complex programs. I already have almost 2 years with Java as my main programming language. From my point of view i am quite ready to start game development. So here is my question. Is Java a good programming language for game development?          I already read a lot of articles that there is no "special language for game programming" and that you should use the one your more comfortable with. But In my expirience making programs with java and deploying them was quite awful, i had to create a launcher with launcher4j and this wasnt working always also there were some permance issues(maybe my fault) but Java doesnt and compatibilities with the JRE.         I tried C# with XNA Framework and it was quite intresting because of my experience with java and Java and C# similarities it was quite easy for me. So I should stick with Java with Slick2d to make a 2D game or I should use C# with XNA? Although i dont know hows XNA deployment. Thank you
  23. Zaphyk

    Slick2D Camera movement

    Thank you very much to everyone i managed make it.
  24. yeah i know slick2d is dead and i should use libGDX but i had trouble setting up it so i decided to use slick, anyway is a test project which was already started and i am gonna use libGDX on the real one.  Lets get to the topic, which is the way of making a camera in a 2d enviroment, the camera should follow the player like this. I´ve searched and i found a way which was moving the map instead but this gave me a few questions. Is moving the map the only way? What happens if the game is multiplayer?  
  25. Zaphyk

    Slick2D Camera movement

    So i should create a camera class containing its x, y ,width, height and whenever i render should check if is inside its bounds before doing it. right? I didint get the part about collision, if i am always moving the map instead of the player how would i detect when the player is in front of a rock or at the boundaries of the map?
  • 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!