Click here to Skip to main content
15,891,033 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Program Pin
Rajesh R Subramanian17-Jan-07 18:23
professionalRajesh R Subramanian17-Jan-07 18:23 
AnswerRe: Program Pin
Hamid_RT17-Jan-07 18:37
Hamid_RT17-Jan-07 18:37 
QuestionRenaming a dll Pin
Manasi D17-Jan-07 18:16
Manasi D17-Jan-07 18:16 
AnswerRe: Renaming a dll Pin
Rajesh R Subramanian17-Jan-07 18:21
professionalRajesh R Subramanian17-Jan-07 18:21 
QuestionA Profiler for MFC apps? Pin
devvvy17-Jan-07 16:20
devvvy17-Jan-07 16:20 
AnswerRe: A Profiler for MFC apps? Pin
_AnsHUMAN_ 17-Jan-07 18:19
_AnsHUMAN_ 17-Jan-07 18:19 
GeneralAny alternative? Does BoundsChecker work with VC6? Re: A Profiler for MFC apps? Pin
devvvy9-Apr-07 16:48
devvvy9-Apr-07 16:48 
QuestionOpenGl Normals reading Pin
zqueezy17-Jan-07 13:57
zqueezy17-Jan-07 13:57 
heyhey,
hope this is the correct forum, cause actually it's a mixture of c++ and opengl question:
I used a 3ds-model-reader (http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=506)
which reads out all vertices correct from the file.
then the normals are calculated and stored.

I want to try my skills with my own lighting calculations but the problem is I cannot read out the normals correctly.
The vertices are no problem, but here's some code:

<br />
{...}<br />
for (int i = 0; i < ModelToDraw.numObjects; i++)<br />
{<br />
	// Enable texture coordiantes, normals, and vertices arrays<br />
	if (ModelToDraw.Objects[i].textured)<br />
		glEnableClientState(GL_TEXTURE_COORD_ARRAY);<br />
	//if (ModelToDraw.lit)<br />
	//	glEnableClientState(GL_NORMAL_ARRAY);<br />
	glEnableClientState(GL_VERTEX_ARRAY);<br />
		// Point them to the t.Objects arrays<br />
	if (ModelToDraw.Objects[i].textured)<br />
		glTexCoordPointer(2, GL_FLOAT, 0, ModelToDraw.Objects[i].TexCoords);<br />
	//if (ModelToDraw.lit)														//	glNormalPointer(GL_FLOAT, 0, ModelToDraw.Objects[i].Normals);<br />
	glVertexPointer(3, GL_FLOAT, 0, ModelToDraw.Objects[i].Vertexes);<br />
	float *pVertex = ModelToDraw.Objects[i].Vertexes;<br />
	float *pNormal = ModelToDraw.Objects[i].Normals;<br />
	//int numNormals = ModelToDraw.Objects[i].numVerts;<br />
	// Loop through the faces as sorted by material and draw them<br />
	for (int j=0; j < ModelToDraw.Objects[i].numMatFaces; j++)<br />
	{<br />
		// ModelToDraw.Materials[ModelToDraw.Objects[i].MatFaces[j].MatIndex].tex.Use();				<br />
		glPushMatrix();<br />
		// Move the model<br />
		glTranslatef(ModelToDraw.Objects[i].pos.x, ModelToDraw.Objects[i].pos.y, ModelToDraw.Objects[i].pos.z);<br />
<br />
		// Rotate the model<br />
		//glRotatef(t.Objects[i].rot.x, 1.0f, 0.0f, 0.0f);<br />
		//glRotatef(t.Objects[i].rot.y, 0.0f, 1.0f, 0.0f);<br />
		//glRotatef(t.Objects[i].rot.z, 0.0f, 0.0f, 1.0f);<br />
		glRotatef(ModelToDraw.Objects[i].rot.z, 0.0f, 0.0f, 1.0f);<br />
		glRotatef(ModelToDraw.Objects[i].rot.y, 0.0f, 1.0f, 0.0f);<br />
		glRotatef(ModelToDraw.Objects[i].rot.x, 1.0f, 0.0f, 0.0f);<br />
<br />
		// Draw the faces using an index to the vertex array<br />
		myGetTriangles(ModelToDraw.Objects[i].MatFaces[j].numSubFaces, ModelToDraw.Objects[i].MatFaces[j].subFaces, pVertex, pNormal, ModelToDraw.shownormals);<br />
		//glDrawElements(GL_TRIANGLES, ModelToDraw.Objects[i].MatFaces[j].numSubFaces, GL_UNSIGNED_SHORT, ModelToDraw.Objects[i].MatFaces[j].subFaces);<br />
		glPopMatrix();<br />
	}<br />
{...}<br />

well this part of code works well with the glDrawElements-Call at the End but I want to use my own function "myGetTriangles", so here's a little snippet:

<br />
{...}<br />
void myGetTriangles(...)<br />
vector4 a,b,c,d;<br />
<br />
int i;<br />
unsigned short index;<br />
float* _tempArray;		<br />
glDisable(GL_LIGHTING);<br />
<br />
for(i=0; i < numSubFaces; i+=3)<br />
{<br />
	index = subFaces[i];		// Pointer to the vertex of the triangle<br />
	_tempArray=(float*)(((char*)k) + index * 12);	// 12 = size of 3 floats<br />
		<br />
	// Get First Triangle Vector<br />
	a.x = _tempArray[0];<br />
	a.y = _tempArray[1];<br />
	a.z = _tempArray[2];<br />
	a.w = 1.0f;<br />
		<br />
	// Read out 2nd Triangle vector<br />
	index = subFaces[i+1];		<br />
	_tempArray=(float*)(((char*)k) + index * 12);	// 12 = sizeof 3 floats<br />
	b.x = _tempArray[0];<br />
	b.y = _tempArray[1];<br />
	b.z = _tempArray[2];<br />
	b.w = 1.0f;<br />
		<br />
	// Read out 3rd Triangle vector<br />
	index = subFaces[i+2];		<br />
	_tempArray=(float*)(((char*)k) + index * 12);	// 12 = size of 3 floats<br />
	c.x = _tempArray[0];<br />
	c.y = _tempArray[1];<br />
	c.z = _tempArray[2];<br />
	c.w = 1.0f;<br />
<br />
	// Get Normalen Vector:<br />
	_tempArray=(float*)pNormals;		// HERE MUST BE THE ERROR<br />
		<br />
	d.x = _tempArray[0];<br />
	d.y = _tempArray[1];<br />
	d.z = _tempArray[2];<br />
	d.w = 1.0f;<br />
		<br />
	if (showNormal)<br />
	{<br />
		glColor3f(1.0, 0.0, 0.0);<br />
		glBegin(GL_LINES);<br />
			glVertex3f(a.x, a.y, a.z);<br />
			glVertex3f(a.x + d.x, a.y + d.y, a.z + d.z);<br />
		glEnd();<br />
	}<br />


I marked the line which must be wrong! I tried several versions but couldn't fix it, any idea?

I think the problem is simply reading the normal from it's pointer but since the drawing method described at the top iterates through the materials I cannot simply alternate through the bunch of arrays.

This problem is nagging me for days, so any advice would be appreciated. thanx guys great forum! Cool | :cool:
Questionfrom vc2005 to vc 2003 porting Pin
OAKmaden17-Jan-07 12:41
OAKmaden17-Jan-07 12:41 
AnswerRe: from vc2005 to vc 2003 porting Pin
Hamid_RT17-Jan-07 18:57
Hamid_RT17-Jan-07 18:57 
QuestionMSDN Pin
Waldermort17-Jan-07 10:16
Waldermort17-Jan-07 10:16 
AnswerRe: MSDN Pin
Mark Salsbery17-Jan-07 11:10
Mark Salsbery17-Jan-07 11:10 
QuestionHook Print Dialog in Word Pin
pgibson00770017-Jan-07 8:17
pgibson00770017-Jan-07 8:17 
QuestionTimer event in MFC Pin
suresh000917-Jan-07 7:31
suresh000917-Jan-07 7:31 
QuestionRe: Timer event in MFC Pin
Mark Salsbery17-Jan-07 7:44
Mark Salsbery17-Jan-07 7:44 
AnswerRe: Timer event in MFC Pin
suresh000917-Jan-07 8:13
suresh000917-Jan-07 8:13 
QuestionRe: Timer event in MFC Pin
David Crow17-Jan-07 8:18
David Crow17-Jan-07 8:18 
AnswerRe: Timer event in MFC Pin
suresh000917-Jan-07 8:25
suresh000917-Jan-07 8:25 
GeneralRe: Timer event in MFC Pin
CPallini17-Jan-07 8:21
mveCPallini17-Jan-07 8:21 
AnswerRe: Timer event in MFC Pin
suresh000917-Jan-07 8:20
suresh000917-Jan-07 8:20 
AnswerRe: Timer event in MFC Pin
suresh000917-Jan-07 8:28
suresh000917-Jan-07 8:28 
QuestionRe: Timer event in MFC Pin
CPallini17-Jan-07 8:15
mveCPallini17-Jan-07 8:15 
AnswerRe: Timer event in MFC Pin
suresh000917-Jan-07 8:26
suresh000917-Jan-07 8:26 
GeneralRe: Timer event in MFC Pin
Mark Salsbery17-Jan-07 8:42
Mark Salsbery17-Jan-07 8:42 
AnswerRe: Timer event in MFC Pin
#realJSOP17-Jan-07 11:36
mve#realJSOP17-Jan-07 11:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.