Results 1 to 3 of 3

Thread: Culling Math

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2002
    Posts
    9

    Culling Math

    I need to take some math classes I think. In the meantime... I have a 'how do I...' question.

    I have a player position (P), and a player direction vector (D).

    I want to make 4 planes, that are view frustum planes (excluding near and far planes). Left (L), Right (R), Top (T), and Bottom (B).

    Now, all I have to do, is set the normal of the clipping planes to (D). Then, I rotate the plane how I want it. My problem is, the player is not at coordinate 0, 0, 0. So, I have to set the 'D' (distance from origin) attribute of the planes. But, how do I figure this?

    Code :
               y
               |
        P      |
        |      |
               |
               |
    x----------|-----------
               |
               |
               |
               |
               |
    So in the crappy diagram above, the player is P and the line from P points in the direction he is facing. How do I get planes set up so it's like an upside down 'V' with the planes meeting at the player's position?

    Keith Jackson

  2. #2
    Senior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    Melbourne, Australia
    Posts
    224

    Re: Culling Math

    Hi.
    Here's how I do it:
    As input it takes player's origin and his (her ) view direction, so this should be what you need.
    Code :
    void Frustum_c::Build(const Vec3_c &Origin, const Vec3_c &View)
    {
    	Matrix_c M1, M2;
     
    	this->Origin = Origin;
     
    	glGetFloatv(GL_PROJECTION_MATRIX, M1);
    	glGetFloatv(GL_MODELVIEW_MATRIX, M2);
     
    	M1.Mult(M2);
     
    	// Near Plane
    	Planes[0].Normal = View;
    	Planes[0].Distance = this->Origin.Dot( View );
     
    	// Left Plane 
    	Planes[1].Normal[0] = M1[3] + M1[0];
    	Planes[1].Normal[1] = M1[7] + M1[4];
    	Planes[1].Normal[2] = M1[11] + M1[8];
    	Planes[1].Distance = -M1[15] - M1[12];
     
    	// Bottom Plane 
    	Planes[2].Normal[0] = M1[3] + M1[1];
    	Planes[2].Normal[1] = M1[7] + M1[5];
    	Planes[2].Normal[2] = M1[11] + M1[9];
    	Planes[2].Distance = -M1[15] - M1[13];
     
    	// Top Plane 
    	Planes[3].Normal[0] = M1[3] - M1[1];
    	Planes[3].Normal[1] = M1[7] - M1[5];
    	Planes[3].Normal[2] = M1[11] - M1[9];
    	Planes[3].Distance = -M1[15] + M1[13];
     
    	// Right Plane 
    	Planes[4].Normal[0] = M1[3] - M1[0];
    	Planes[4].Normal[1] = M1[7] - M1[4];
    	Planes[4].Normal[2] = M1[11] - M1[8];
    	Planes[4].Distance = M1[12] - M1[15];
     
    	// Normalize them
    	for (int i = 0; i < 5; i++)
    	{
    		Planes[i].Normalize();
    	}
    }
    Hope it helps.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    Melbourne, Australia
    Posts
    224

    Re: Culling Math

    Ah, I need to add something - it assumes you have all of your translations set through OpenGL, so you can read in matrices.

Similar Threads

  1. 3D math lib
    By glnoob_andre in forum OpenGL: General
    Replies: 3
    Last Post: 02-06-2012, 12:15 PM
  2. Hi... About 3d math...
    By Magneto3D in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 11-10-2002, 07:32 AM
  3. math
    By in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 04-10-2002, 05:18 AM
  4. Math API?
    By in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 09-07-2001, 01:36 PM
  5. Help! What math do I need to do 3D ?
    By imported_newbie in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 10-11-2000, 08:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean