Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


calculating normal


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 marcus12   Members   -  Reputation: 252

Like
0Likes
Like

Posted 22 August 2011 - 08:01 AM

Hi,
I am a beginner in opengl and maths.

I want to find the normal of the plane drawn :

   	glBegin(GL_QUADS);
           glVertex2f(700.0f, 500.0f);
           glVertex2f(720.0f, 500.0f);
           glVertex2f(720.0f, 300.0f);
           glVertex2f(700.0f, 300.0f);
       glEnd();

I am trying to find collision detection using ray cast.

All suggestions are welcome.

Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 8430

Like
0Likes
Like

Posted 22 August 2011 - 08:17 AM

Your quad is exclusively in the XY-plane, so the normal vector is the Z-axis; either (0,0,1) or (0,0,-1) depending on what you consider to be the front of it.

In general though, the normal can be calculated from the cross product of two non-linearly dependent vectors on your face. You can, for example, take two edges (the vector between two pairs of vertices), and calculate the normal as the cross product of the two vectors.

#3 mrchrismnh   Members   -  Reputation: 82

Like
1Likes
Like

Posted 22 August 2011 - 08:26 AM

For a plane normal you need a third dimension. Then you take two edges of the plane that share the same corners, make vectors of them, take the cross product of those vectors and then normalize the cross product. So let's give your plane a z axis... and put them in a vertex (pseudo) class so the data can be manipulated by us...

vertice plane_a(700.0f, 500.0f,0.0f);
vertice plane_b(720.0f, 500.0f,0.0f);
vertice plane_c(720.0f, 300.0f,0.0f);
vertice plane_d(700.0f, 300.0f,0.0f);

vector a(a,c);
vector b(b,c);//these constructors are defined as head - tail so the vector here is going to be c.x - b.x, c.y - b.y, c.z - b.z

vector crossvec = crossprod(a,b);
//crossprod is:
// Cx = AyBz - AzBy
//Cy = AzBx - AxBz
//Cz = AxBy - AyBx

//now you want to normalize the crossproduct you do that via sqrt(x^2 + y^2 + z^2) and then divide each of its coordinates by the value obtained. Last but not least you add the resultant vector (which is going to be 0,0,1 or ideally close to it) to one of the planes four vertices. Yeah, the normal here is one along the z but the method I described works for any plane orientation.



"It's like naming him Asskicker Monstertrucktits O'Ninja" -Khaiy


#4 FlyingDutchman   Members   -  Reputation: 207

Like
1Likes
Like

Posted 22 August 2011 - 04:55 PM

good work! like straight out of the book :-)

For a plane normal you need a third dimension. Then you take two edges of the plane that share the same corners, make vectors of them, take the cross product of those vectors and then normalize the cross product. So let's give your plane a z axis... and put them in a vertex (pseudo) class so the data can be manipulated by us...

vertice plane_a(700.0f, 500.0f,0.0f);
vertice plane_b(720.0f, 500.0f,0.0f);
vertice plane_c(720.0f, 300.0f,0.0f);
vertice plane_d(700.0f, 300.0f,0.0f);

vector a(a,c);
vector b(b,c);//these constructors are defined as head - tail so the vector here is going to be c.x - b.x, c.y - b.y, c.z - b.z

vector crossvec = crossprod(a,b);
//crossprod is:
// Cx = AyBz - AzBy
//Cy = AzBx - AxBz
//Cz = AxBy - AyBx

//now you want to normalize the crossproduct you do that via sqrt(x^2 + y^2 + z^2) and then divide each of its coordinates by the value obtained. Last but not least you add the resultant vector (which is going to be 0,0,1 or ideally close to it) to one of the planes four vertices. Yeah, the normal here is one along the z but the method I described works for any plane orientation.




I open sourced my C++/iOS OpenGL 2D RPG engine :-)


See my blog: (Tutorials and GameDev)

http://howtomakeitin....wordpress.com/





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS