Jump to content

  • Log In with Google      Sign In   
  • Create Account

masterbubu

Member Since 27 Aug 2009
Offline Last Active Jul 31 2013 11:58 AM

Topics I've Started

Frustum Culling - Need help

15 March 2013 - 03:59 AM

Hi,

 

I'm trying to implement frustum culling on opengl ES. I have read online tutorials 

 

http://www.crownandcutlass.com/features/technicaldetails/frustum.html

http://zach.in.tu-clausthal.de/teaching/cg_literatur/lighthouse3d_view_frustum_culling/index.html

 

and it looks straightforward. But has you can see on the video capture, it does not work well.

 

http://www.screencast.com/t/e6L2JYJapzb

 

Here is my build planes function:

 

void CFrustum::BuildPlanes( const mat4& ModelView, const mat4& Proj )
{
	mat4 clip, modl = ModelView, proj = Proj;
	float t = 0;

   clip[ 0] = modl[ 0] * proj[ 0] + modl[ 1] * proj[ 4] + modl[ 2] * proj[ 8] + modl[ 3] * proj[12];
   clip[ 1] = modl[ 0] * proj[ 1] + modl[ 1] * proj[ 5] + modl[ 2] * proj[ 9] + modl[ 3] * proj[13];
   clip[ 2] = modl[ 0] * proj[ 2] + modl[ 1] * proj[ 6] + modl[ 2] * proj[10] + modl[ 3] * proj[14];
   clip[ 3] = modl[ 0] * proj[ 3] + modl[ 1] * proj[ 7] + modl[ 2] * proj[11] + modl[ 3] * proj[15];

   clip[ 4] = modl[ 4] * proj[ 0] + modl[ 5] * proj[ 4] + modl[ 6] * proj[ 8] + modl[ 7] * proj[12];
   clip[ 5] = modl[ 4] * proj[ 1] + modl[ 5] * proj[ 5] + modl[ 6] * proj[ 9] + modl[ 7] * proj[13];
   clip[ 6] = modl[ 4] * proj[ 2] + modl[ 5] * proj[ 6] + modl[ 6] * proj[10] + modl[ 7] * proj[14];
   clip[ 7] = modl[ 4] * proj[ 3] + modl[ 5] * proj[ 7] + modl[ 6] * proj[11] + modl[ 7] * proj[15];

   clip[ 8] = modl[ 8] * proj[ 0] + modl[ 9] * proj[ 4] + modl[10] * proj[ 8] + modl[11] * proj[12];
   clip[ 9] = modl[ 8] * proj[ 1] + modl[ 9] * proj[ 5] + modl[10] * proj[ 9] + modl[11] * proj[13];
   clip[10] = modl[ 8] * proj[ 2] + modl[ 9] * proj[ 6] + modl[10] * proj[10] + modl[11] * proj[14];
   clip[11] = modl[ 8] * proj[ 3] + modl[ 9] * proj[ 7] + modl[10] * proj[11] + modl[11] * proj[15];

   clip[12] = modl[12] * proj[ 0] + modl[13] * proj[ 4] + modl[14] * proj[ 8] + modl[15] * proj[12];
   clip[13] = modl[12] * proj[ 1] + modl[13] * proj[ 5] + modl[14] * proj[ 9] + modl[15] * proj[13];
   clip[14] = modl[12] * proj[ 2] + modl[13] * proj[ 6] + modl[14] * proj[10] + modl[15] * proj[14];
   clip[15] = modl[12] * proj[ 3] + modl[13] * proj[ 7] + modl[14] * proj[11] + modl[15] * proj[15];

   /* Extract the numbers for the RIGHT plane */
   vPlanes[0][0] = clip[ 3] - clip[ 0];
   vPlanes[0][1] = clip[ 7] - clip[ 4];
   vPlanes[0][2] = clip[11] - clip[ 8];
   vPlanes[0][3] = clip[15] - clip[12];

   /* Normalize the result */
   t = sqrt( vPlanes[0][0] * vPlanes[0][0] + vPlanes[0][1] * vPlanes[0][1] + vPlanes[0][2] * vPlanes[0][2] );
   vPlanes[0][0] /= t;
   vPlanes[0][1] /= t;
   vPlanes[0][2] /= t;
   vPlanes[0][3] /= t;

   /* Extract the numbers for the LEFT plane */
   vPlanes[1][0] = clip[ 3] + clip[ 0];
   vPlanes[1][1] = clip[ 7] + clip[ 4];
   vPlanes[1][2] = clip[11] + clip[ 8];
   vPlanes[1][3] = clip[15] + clip[12];

   /* Normalize the result */
   t = sqrt( vPlanes[1][0] * vPlanes[1][0] + vPlanes[1][1] * vPlanes[1][1] + vPlanes[1][2] * vPlanes[1][2] );
   vPlanes[1][0] /= t;
   vPlanes[1][1] /= t;
   vPlanes[1][2] /= t;
   vPlanes[1][3] /= t;

   /* Extract the BOTTOM plane */
   vPlanes[2][0] = clip[ 3] + clip[ 1];
   vPlanes[2][1] = clip[ 7] + clip[ 5];
   vPlanes[2][2] = clip[11] + clip[ 9];
   vPlanes[2][3] = clip[15] + clip[13];

   /* Normalize the result */
   t = sqrt( vPlanes[2][0] * vPlanes[2][0] + vPlanes[2][1] * vPlanes[2][1] + vPlanes[2][2] * vPlanes[2][2] );
   vPlanes[2][0] /= t;
   vPlanes[2][1] /= t;
   vPlanes[2][2] /= t;
   vPlanes[2][3] /= t;

   /* Extract the TOP plane */
   vPlanes[3][0] = clip[ 3] - clip[ 1];
   vPlanes[3][1] = clip[ 7] - clip[ 5];
   vPlanes[3][2] = clip[11] - clip[ 9];
   vPlanes[3][3] = clip[15] - clip[13];

   /* Normalize the result */
   t = sqrt( vPlanes[3][0] * vPlanes[3][0] + vPlanes[3][1] * vPlanes[3][1] + vPlanes[3][2] * vPlanes[3][2] );
   vPlanes[3][0] /= t;
   vPlanes[3][1] /= t;
   vPlanes[3][2] /= t;
   vPlanes[3][3] /= t;

   /* Extract the FAR plane */
   vPlanes[4][0] = clip[ 3] - clip[ 2];
   vPlanes[4][1] = clip[ 7] - clip[ 6];
   vPlanes[4][2] = clip[11] - clip[10];
   vPlanes[4][3] = clip[15] - clip[14];

   /* Normalize the result */
   t = sqrt( vPlanes[4][0] * vPlanes[4][0] + vPlanes[4][1] * vPlanes[4][1] + vPlanes[4][2] * vPlanes[4][2] );
   vPlanes[4][0] /= t;
   vPlanes[4][1] /= t;
   vPlanes[4][2] /= t;
   vPlanes[4][3] /= t;

   /* Extract the NEAR plane */
   vPlanes[5][0] = clip[ 3] + clip[ 2];
   vPlanes[5][1] = clip[ 7] + clip[ 6];
   vPlanes[5][2] = clip[11] + clip[10];
   vPlanes[5][3] = clip[15] + clip[14];

   /* Normalize the result */
   t = sqrt( vPlanes[5][0] * vPlanes[5][0] + vPlanes[5][1] * vPlanes[5][1] + vPlanes[5][2] * vPlanes[5][2] );
   vPlanes[5][0] /= t;
   vPlanes[5][1] /= t;
   vPlanes[5][2] /= t;
   vPlanes[5][3] /= t;

}

 

 

The camera is a simple FPS cam, that uses produces lookat matrix for ( Pos, Up, Forward ).

 

I use this function to check the sphere collision with the frustum

 

int CFrustum::SphereInFrustum( float x, float y, float z, float radius )
{
   int p;
   int c = 0;
   float d;

   for( p = 0; p < NUM_PLANES; p++ )
   {
      d = vPlanes[p][0] * x + vPlanes[p][1] * x + vPlanes[p][2] * z + vPlanes[p][3];
      if( d <= -radius )
         return 0;
      if( d > radius )
         c++;
   }
   return (c == 6) ? 2 : 1;
}

 

 

 

What I'm doing wrong? it is all seems to be the same as the tutorials.


Gpu skinning and VBO

07 March 2013 - 12:57 AM

Hi,

 

I have used for some time a gpu skeleton system that preforms well with vertex arrays.

 

I decided to try use VBOs, with the same setup as I have now,and just replace the vertex arrays with VBOs. ( vertices, weights, indices ).

 

For some reason the I get bad deformations. 

 

However, if I keep the vertices data on vbo, and the weights/indices at vertex arrays, the renders looks fine.

 

I'm asking for some direction to explore, assuming that the weights and the indices are stored properly on the VBOs,

 

is the data on VA stored differently then VBO? I'm just trying to figure what can cause the problem.

 

tnx smile.png

 

 

 


Ray Picking - Need help.

11 December 2012 - 03:34 AM

Hi,

I'm trying for long time to implement picking ray.
I read lots of tutorials online, but still did not managed to make to work properly.

I'm created the near/far points using unproject method ( that works exactly the same as gluunproject does).
then I created the ray and check for intersection with the bounding box.

For visual reference I draw the ray. it looks like the ray does not comes out from the mouse cursor toward the scene.

Please help me in here.

tnx



int UnProject(float winx, float winy, float winz, const Matrix4f *modelview, const Matrix4f *projection, int viewport[4], Vector3f *objectCoordinate)
  {
	const m44<f32>& inverseVP = (*projection * *modelview).inverse();
	Vector4f in( (winx-(float)viewport[0])/(float)viewport[2]*2.0-1.0,
	  (winy-(float)viewport[1])/(float)viewport[3]*2.0-1.0,
	   2.0*winz-1.0,
	 1.0 );
  Vector4f out = inverseVP * in;
  if(out.w == 0.0f)
		 return 0;
	  out[3]=1.0/out[3];
   objectCoordinate->x=out.x*out.w;
	  objectCoordinate->y=out.y*out.w;
	  objectCoordinate->z=out.z*out.w;
	  return 1;
  }

  void sRay::Create( const int& MouseX,
	   const int& MouseY,
	   NS_CAMERA::sCamera* pCamera )
{
int viewport[4] = {0,0,WINDOW_WIDTH, WINDOW_HIGHT };
Vector3f _near;
Vector3f _far;
UnProject(MouseX, viewport[3]-MouseY,0,&pCamera->GetViewMatrix(),&pCamera->GetProjectionMatrix(),viewport,&_near); // get coords
UnProject(MouseX, viewport[3]-MouseY,1,&pCamera->GetViewMatrix(),&pCamera->GetProjectionMatrix(),viewport,&_far);
m_Direction = (_far - _near).normalize();
m_Origen = *pCamera->GetCameraPos();
}

void sRay::Render( NS_CAMERA::sCamera* pCamera )
{
Vector3f p0 = m_Origen;
Vector3f p1 =  pCamera->fZFar *m_Direction;
// Drawing the line using OGL...
}

Creating OBB

31 October 2012 - 09:04 AM

Hi all,

I'm trying to create an OBB for my engine but failed to do so.

I have read good articles/tutorials on line, and I think I understand the concept, but still the OBB does not look good.

The algorithm I use:

for each vertex on the mesh vertices do:
m+= vertex

m/= vertices.size()

Now calculation the covariance matrix:

for each vertex on the mesh vertices do:
{

upperRight3x3Triangle[0] += p.x*p.x - m.x*m.x;
upperRight3x3Triangle[1] += p.x*p.y - m.x*m.y;
upperRight3x3Triangle[2] += p.x*p.z - m.x*m.z;
upperRight3x3Triangle[3] += p.y*p.y - m.y*m.y;
upperRight3x3Triangle[4] += p.y*p.z - m.y*m.z;
upperRight3x3Triangle[5] += p.z*p.z - m.z*m.z;
}

basically I have computed the upper right triangle of the covariance matrix.

Then I just create the matrix from those values, so that the lower triangle of the matrix is symmetrical to the upper triangle.

My problem is that according to the resources I have read, this matrix has the form of [ Right, Up, Forward ] (3x3 rotation matrix ),

Those 3 axes that represents the OBB orientations should be orthogonal to each other ( because the matrix is symmertic ). I have draw

the box axes, and they are not orthogonal to each other.

what am I missing ?

Any help/reference would be great.

tnx a lot

Multiple Lights flickering problem - Iphone4s, Ipad2/3

02 August 2012 - 04:54 AM

Hi,

I have a problem with multiple lights which only happens with the latest Apple's devices such as Iphone 4s, Ipad2/3.
For older devices it is working perfectly ( such as iphone 4 and ipod ).

the problem is the flickers of the scene ( see attached ).

I have edit the shader, and change the loop:
for( int i = 0; i < NUM_LIGHTS; ++i ) --> for( int i = 0; i < 1; ++i ) and it worked ( but with only 1 light).

then I changed the index if the light ( just to see if it is not a light problem ), and it worked for the second light as well.

please note that this code is well working for all Android devices as well.

Any help would be grateful.

Tnx.

PARTNERS