Jump to content
• Advertisement

# OpenGL begginer question

This topic is 4259 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

##### Share on other sites
Advertisement
Quote:
 Original post by k_ounu_eddyWhy 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

##### 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

##### 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

##### Share on other sites
Thanks a lot,now I understand!

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
19
3. 3
4. 4
khawk
14
5. 5
A4L
13
• Advertisement

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633743
• Total Posts
3013643
×

## Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!