• Create Account

# maledivius

Member Since 23 Dec 2010
Offline Last Active Jan 12 2011 05:38 AM

### In Topic: Lesson 28 Triangle Normal

12 January 2011 - 05:37 AM

I did this by adding some arrays and vectors for calculs.

```GLfloat ra[3][99]; //for old vertices
GLfloat rb[3][99]; // for new vertices
GLfloat rn[3][99]; //for normals

GLfloat vn1[3];
GLfloat vn2[3];

GLfloat out1[3];
```

I also needed to change loop for triangle strip.
So now it looks like this:

```for (v=0;v<=divs;v++) {
px = ((float)v)/((float)divs);

glVertex3d(last[v].x, last[v].y, last[v].z);
ra[0][v]=last[v].x;
ra[1][v]=last[v].y;
ra[2][v]=last[v].z;

last[v] = Bernstein(px, temp);
glVertex3d(last[v].x, last[v].y, last[v].z);
rb[0][v]=last[v].x;
rb[1][v]=last[v].y;
rb[2][v]=last[v].z;

}

for (v=0;v<=divs;v++) {
px = ((float)v)/((float)divs);

vn1[0]=ra[0][v+1]-ra[0][v];
vn1[1]=ra[1][v+1]-ra[1][v];
vn1[2]=ra[2][v+1]-ra[2][v];

vn2[0]=rb[0][v]-ra[0][v];
vn2[1]=rb[1][v]-ra[1][v];
vn2[2]=rb[2][v]-ra[2][v];

rn[0][v]=-vn1[1]*vn2[2] + vn1[2]*vn2[1];
rn[1][v]=-vn1[2]*vn2[0] + vn1[0]*vn2[2];
rn[2][v]=-vn1[0]*vn2[1] + vn1[1]*vn2[0];

}

glBegin(GL_TRIANGLE_STRIP);

for (v=0;v<=divs;v++) {
px = ((float)v)/((float)divs);
out1[0]=rn[0][v];
out1[1]=rn[1][v];
out1[2]=rn[2][v];
glTexCoord2f(pyold, px);
glNormal3fv(out1);
glVertex3d(ra[0][v], ra[1][v], ra[2][v]);

glTexCoord2f(py, px);

glVertex3d(rb[0][v], rb[1][v], rb[2][v]);
}
```

I know these are only per-face normnals but when I increase div it's looking good for me.

PARTNERS