Zaphyk

Members
  • Content count

    26
  • Joined

  • Last visited

Community Reputation

292 Neutral

About Zaphyk

  • Rank
    Member

Personal Information

Social

  • Twitter
    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. 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. :)
  4. 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.
  5. 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?
  6. 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? 
  7. 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?
  8. 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?
  9. 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.
  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. OpenGL Skybox

    It was a typo from rewriting my code here, I edited the post fixing the typo
  13. 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. 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. Math behind Glu.UnProject

    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