Jump to content
  • Advertisement
Sign in to follow this  
k_ounu_eddy

OpenGL begginer question

This topic is 4174 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone.I'me a begginer in OpenGL(not in programming),and this is my first thread on this forum. In the second chapter of the Red Book(in the end),is an example of how to build an aproximated sphere from an icosahedron.Here is the link http://fly.cc.fer.hr/~unreal/theredbook/chapter02.html if you don't have this book.This is the code that i don't understand: void subdivide(float *v1, float *v2, float *v3) { GLfloat v12[3], v23[3], v31[3]; GLint i; for (i = 0; i < 3; i++) { v12 = v1+v2; //here I don't understand v23 = v2+v3; v31 = v3+v1; } normalize(v12); normalize(v23); normalize(v31); drawtriangle(v1, v12, v31); drawtriangle(v2, v23, v12); drawtriangle(v3, v31, v23); drawtriangle(v12, v23, v31); } Why where I marked the place,is an addition of v1 and v2?To obtain a vector of two points isn't suppose to make a soustraction?Please help.Thanks!!!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by k_ounu_eddy
Why where I marked the place,is an addition of v1 and v2?To obtain a vector of two points isn't suppose to make a soustraction?Please help.Thanks!!!



It appears that they are finding the Average position between v1 and v2.
Hence they are being added together; a few lines down the result is Normalised, which is analagous to the division step of finding an average.

Share this post


Link to post
Share on other sites
But if they want to find the average position they don't have to multiply by 1/2?I mean this:
v12 = (v1+v2)/2;
But they are don't make like this.Why?

Share this post


Link to post
Share on other sites
I should clarify.

They are finding the the Average Direction of the vectors v1 and v2.
Not the Average Position.

Since v1 and v2 are unit length to begin with, the average direction can be found by adding them together then normalizing the result back to unit length. (this is what they're doing)

This is not the same as finding the average postion, since here the length of the result is discarded as unimportant.


In this case, either method would produce the same result after normalization.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!