• Content count

  • Joined

  • Last visited

Community Reputation

116 Neutral

About caibbor

  • Rank
  1. I've been working on a 3d engine from scratch for a while now. I've got my own model format with an export plugin for blender, and models are importing just fine in game. I'm working with a test model - a Hellknight imported from Doom3 and exported to my own format. The mesh draws as expected in my engine. But now I'm designing animation.   Basically, I'm not sure the right way to go about this, either:   A.) I'll export the skeleton with each bone pose (in world space, not relative to any other bones) as an array for each frame - even non-key-frames. this way, I can just set bone pos and be done with it. However, this will take lots of memory and more disk space than option B or C.   B.) I do the same as above, except export only keyframes, but this time interpolate between bone vertex positions. With this, we'd need more informatiion and processing to do the interpolating so that bones/mesh doesn't deform improperly, since point A to point B would need to be on a curve, not linear. This also would have to be relative to it's parent bone.   C.) Same as option B, except bone head/tail positions will be relative to the parent bone's tail position.   What's the standard way of doing this in decent game engines?
  2. glEnableVertexAttribArray takes am attribute location value which you get with glGetAttribLocation. however, glGetAttribLocation returns a SIGNED integer, and glEnableVertexAttribArray takes an UNsigned integer, as shown by ths following links (and this is how it is implemented in glew): [code]GLint glGetAttribLocation(GLuint  program,  const GLchar * name); void glEnableVertexAttribArray(GLuint  index);[/code] so I ask... "wtf?"   am I overlooking something important?
  3. Unit Cube to Frustum

    even this exaple uses -0.5/0.5 on x and y, and 1/10 as default values on the frustum: [url=""][/url] ( scroll all the way to the bottom, look at the image and it's glFrustum() call ). running this program, it doesn't let you go below 1 for z-near.
  4. Unit Cube to Frustum

    I'm running Linux Mint. This is OpenGL, I assure you. I am, however, using my own 4x4 matrix implementation. i've used libraries like glu as references when implementing these, so they should have identical functionality. I'm not using fixed-functionality pipeline, which is why I wrote this library.
  5. Unit Cube to Frustum

    update: fixed up and confirmed my perspective invert function is working properly. although with -1/1 bounds on all axes like you mentioned, I'm still getting this hour-glass shaped thing.
  6. OpenGL Bottom Row of 4x4 Matrix

    "I always do that. I always mess up some mundane detail." - Michael Bolton, Office Space thanks.
  7. OpenGL Bottom Row of 4x4 Matrix

    alright, then riddle me this. (all in column-major order) The projection matrix I created is: 0.074978 0.000000 0.000000 0.000000 0.000000 0.099970 0.000000 0.000000 0.000000 0.000000 -1.000100 -1.000000 0.000000 0.000000 -0.200010 0.000000 It's inverse I calculated is: 13.337285 0.000000 0.000000 0.000000 0.000000 10.002963 0.000000 0.000000 0.000000 0.000000 0.000000 -4.999750 0.000000 0.000000 -1.000000 20001000.000000 an multiplying those matrices together should be identy, but instead I get: 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 -20000994.000000 1.000000 All code related to this is shown below. I've been up and down and all the methods, as far as I can tell, look correct. [source lang="cpp"]// Mat4f class is a 4x4 matrix of floats. // Mat4f::data is a float[16], and is column-major // returns float& intentionally, method is private inline float& Mat4f::M( const int col, const int row ) { assert( col < dim && row < dim && col >= 0 && row >= 0); return data[row+col*4]; } void Mat4f::Multiply( const Mat4f& mat, Mat4f& out ) const { assert ( &mat != &out ); int r,c; for ( c=0; c<4; c++ ) { for ( r=0; r<4; r++ ) { out.M(c,r) = M(r,0) * mat.M(0,c) + M(r,1) * mat.M(1,c) + M(r,2) * mat.M(2,c) + M(r,3) * mat.M(3,c); } } } // calculation from: void my_glFrustum( float l, float r, float b, float t, float n, float f, Mat4f& out ) { float n2 = n * 2.0f;[0]=n2/(r-l);[1]=0.0f;[2]=0.0f;[3]=0.0f;[4]=0.0f;[5]=n2/(t-b);[6]=0.0f;[7]=0.0f;[8]=(r+l)/(r-l);[9]=(t+b)/(t-b);[10]=-(f+n)/(f-n);[11]=-1.0f;[12]=0.0f;[13]=0.0f;[14]=-(n2*f)/(f-n);[15]=0.0f; } // calculation from: void my_glFrustum_inv( float l, float r, float b, float t, float n, float f, Mat4f& out ) { float n2 = n * 2.0f;[0]=(r-l)/n2;[1]=0.0f;[2]=0.0f;[3]=0.0f;[4]=0.0f;[5]=(t-b)/n2;[6]=0.0f;[7]=0.0f;[8]=0.0f;[9]=0.0f;[10]=0.0f;[11]=-(f-n)/(n2*f);[12]=(r+l)/n2;[13]=(t+b)/n2;[14]=-1.0f;[15]=(f+n)/n2*f; } void my_gluPerspective( float fov, float x,float y,float near,float far, Mat4f& out, bool invert = false ); void my_gluPerspective( float fov, float x,float y,float near,float far, Mat4f& out, bool invert ) { // inspired by [url=""]http://www.cse.unsw....e/frustsrc.html[/url] float aspect = x / y; float t = 1.0f/tanf(fov * 3.141f / 360.0f); if ( invert ) { my_glFrustum_inv(-t * aspect, t * aspect, -t, t, near, far, out); } else { my_glFrustum(-t * aspect, t * aspect, -t, t, near, far, out); } } inline void my_gluPerspective_inv( float fov, float x,float y,float near,float far, Mat4f& out ) { my_gluPerspective( fov, x, y, near, far, out, true ); } int main ( void ) { Mat4f should_be_identity; Mat4f projection; Mat4f projection_inverse; my_gluPerspective(90,800,600,0.1f,2000,projection); my_gluPerspective_inv(90,800,600,0.1f,2000,projection_inverse); projection.Multiply(projection_inverse, should_be_identity); for ( int i=0; i<16; i++ ) printf("%f ",[i] ); /* expected output: 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 actual output: 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 -20000994.000000 1.000000 */ return 0; } [/source]
  8. Unit Cube to Frustum

    I figured that +1/-1 wouldn't be a unit cube.. it would be a unit*2 cube [img][/img] and 0.1 to 1.1 because, like I said, if I use +1/-1 on the z, the nature of the perspective matrix continues to project the cube if it goes behind the camera, makign it look like an hour-glass (my Z axis is up/down) using +1/-1 on the z: [img][/img] using -0.1/-1.1 on the z: [img][/img] all Vec3's when multiplied by a 4x4 matrix assume a w of 1. But, it seems I am inverting my projection matrix incorrectly, as discussed later in the conversation here:
  9. OpenGL Bottom Row of 4x4 Matrix

    [quote name='Brother Bob' timestamp='1355781685' post='5011829'] But take a look at how OpenGL's matrices are commonly designed [url=""]here[/url] in appendix F. It lists their inverse also. [/quote] I tried implementing my own fucntions to generate a matrix based on those equations, as well as an inverse: [img][/img] Multiplying a matrix together with it's own inverse should result in an identity matrix. I'm getting mostly identity, except col 3 row 4 is always -5.9, and col 4 row 3 is always -1.2. I've tripple-checked that my matrices match the ones in the image. I think the problem is in my matrix multiplication. I know how to multiply the 3x3 rotation section of the matrix and then add the translation, but what do I do with the perspective section? Edit: I've been googling and even looked into a few CG programming books. nobody seems to say how to handle the bottom row of a GL 4x4 when multiplying two matrices together...
  10. Unit Cube to Frustum

    it might fit in the Math section better, I just figured I'm using opengl-style matrices as opposed to any other, and perspective/projection is more of a computer graphics thing than mathematics, so... I'm not sure. I am trying to apply a perspective projection to a unit cube so that it becomes a view frustum, for view frustum culling in my octree. I'm sorry I forgot to mention it's a "view frustum" in the title - editing it now. edit: not sure I can change the title of the thread.
  11. I've found countless threads, articles, etc about this topic, but I'm not doing something right. I can create a view frustum but it isn't on the shape of the 'view' (it's much much wider) I'll explain my process here as best I can without getting too deep into the math. if everything here checks out, I'll look closer at those operations. steps I take: 1.) create a unit cube (8 vertices) with these bounds: min/max x: -0.5f to 0.5f min/max y: -0.5f to 0.5f min/max z: -0.1f to -1.1f (if z ranges from positive to negative, the frustum becomes more like an hour glass) 2.) invert my projection matrix 3.) multiply each of my cube's vertices by this inverted projection matrix 4.) ... 5.) profit I don't know how to apply the view resolution like 800x600 because the thing is already pretty big at this point, with the smallest face of the frustum (the screen) being slightly larger than the actual screen space.
  12. OpenGL Bottom Row of 4x4 Matrix

    thank you, larspensjo. I was delighted to find octave available for my linux distro. but how about projection/perspective matrices? I presume the way to invert the perspective section of a matrix is to just negate the values, just the same as negating the translation parts. is this correct?
  13. OpenGL Bottom Row of 4x4 Matrix

    I'm curious... what program are you using there in the last post? has some interesting notation
  14. OpenGL Bottom Row of 4x4 Matrix

    oh wow, that's easy. thank you very much! sometimes it takes baby-speak and sock puppets to explain things to me