Click here to Skip to main content
15,895,084 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCase Sensitive Pin
Chatura Dilan25-Jul-06 16:48
Chatura Dilan25-Jul-06 16:48 
AnswerRe: Case Sensitive Pin
Steve Echols25-Jul-06 19:13
Steve Echols25-Jul-06 19:13 
QuestionRe: Case Sensitive Pin
Hamid_RT25-Jul-06 19:31
Hamid_RT25-Jul-06 19:31 
AnswerRe: Case Sensitive Pin
Chatura Dilan25-Jul-06 22:13
Chatura Dilan25-Jul-06 22:13 
QuestionRe: Case Sensitive Pin
David Crow27-Jul-06 2:46
David Crow27-Jul-06 2:46 
QuestionImplementing a custom Dialogbox Pin
Kamal Shankar25-Jul-06 15:59
Kamal Shankar25-Jul-06 15:59 
AnswerRe: Implementing a custom Dialogbox Pin
spacecadet1025-Jul-06 16:25
spacecadet1025-Jul-06 16:25 
QuestionNeed help with ported c++ triangulation routine [modified] Pin
spacecadet1025-Jul-06 15:02
spacecadet1025-Jul-06 15:02 
Hey,

I have been converting a application from watcom/dos4gw/metagraphics over to vc++/MFC. i should mention that before i started (6 months ago) i had only programmed in basic and didn't understand c/c++ at all.

The program used to create a 3D model stored in an array, and then rendered it to the screen using a simple wireframe view and a sloooow BSP routine.
the hiddenline(BSP) functions are taken from a book written in the 80's and they are a complete mess, and for some reason run like 3/4 times slower on a 1500mhz windows machine than on a 350mhz DOS laptop?!? so anyway, instead of trying to understand this sytem and then converting it, i have created a DirectX Vertice buffer directly from the raw model Polygons. To create the buffers i adapted the old triangulation function to work with my data (without fully understanding it!), and then adapted a vector normal calculation routine from another (working) application.

To get a polygon triangulated correctly i have to rotate it twice, yaw then pitch, before the triangulation function finds any triangles, this is a copy of the vertice buffer the original is left unrotated. the function creates an array of triangles{A,B,C} that link to the vertice buffers. the vector normals are then calculated for each point in each triangle and a DX buffer is created.
After alot of hair pulling i finally got this to work however....
The Z buffer operation never works properly, objects behind are partially shown in front of other objects. i have tried all modes.
The Backface culling mostly works but removes some polygons that it shouldn't.
The lighting/shading is in oppposite directions for triangles in the same polygon.

Picture : http://www.rayevansengineering.com/Surreal/Conservatory.jpg[^]

I have no idea where the problem lies at the moment, after reading some stuff around the net i suspect it has something to do with the vector normals. or is it the fact that the point buffers are rotated for triangulation but not for rendering? maybe the triangulation function is arranging the points in some weird order?
Am i missing something else entirely? do the triangles in a polygon need merging somehow when creating the normals?


VECTOR NORMAL ROUTINE
				vector1=pVertices[nOrigin].p-pVertices[nOrigin+1].p;<br />
				vector2=pVertices[nOrigin].p-pVertices[nOrigin+2].p;<br />
				// Calculate Vector Cross Product<br />
				D3DXVec3Cross(&temp,&vector1,&vector2);<br />
				// Store Normalized Vector into vertice 0 of current triangle<br />
				D3DXVec3Normalize(&pVertices[nOrigin].normal,&temp);<br />
<br />
				// Copy normalized vector to all points<br />
				pVertices[nOrigin+1].normal=pVertices[nOrigin].normal;<br />
				pVertices[nOrigin+2].normal=pVertices[nOrigin].normal;<br />
<br />


PRE TRIANGULATION ROTATE
// Calc yaw angle<br />
ang=geo.AngleXZ(newpoly.m_coord[p1],newpoly.m_coord[p2]);<br />
//afxDump <<""<< m_poly[i].m_yaw <<" "<< ang <<"\n";<br />
//rotate yaw!<br />
for (a=0;a<newpoly.m_npoints;a++) <br />
    newpoly.m_coord[a].Rotate(newpoly.m_coord[p1],0,0,-ang,newpoly.m_coord[a]);<br />
// Calc Pitch angle<br />
pitch=atan2((newpoly.m_coord[p3].y-newpoly.m_coord[p2].y),(newpoly.m_coord[p2].z-newpoly.m_coord[p3].z))/RAD;<br />
pitch=-(90-pitch);        <br />
//afxDump <<""<< m_poly[i].m_pitch <<" "<< pitch <<"\n";<br />
//rotate pitch!<br />
for (a=0;a<newpoly.m_npoints;a++) <br />
    newpoly.m_coord[a].Rotate(newpoly.m_coord[p1],pitch,0,0,newpoly.m_coord[a]);<br />


THE TRIANGULATION ROUTINE
[made the message huge] - can post if needed

-- modified at 21:38 Tuesday 25th July, 2006
AnswerRe: Need help with ported c++ triangulation routine Pin
Steve Echols25-Jul-06 20:35
Steve Echols25-Jul-06 20:35 
GeneralRe: Need help with ported c++ triangulation routine Pin
spacecadet1029-Jul-06 16:54
spacecadet1029-Jul-06 16:54 
Questionmfc drawing philosophy question - when is the correct time to draw? Pin
charlieg25-Jul-06 14:10
charlieg25-Jul-06 14:10 
AnswerRe: mfc drawing philosophy question - when is the correct time to draw? Pin
User 58385225-Jul-06 15:09
User 58385225-Jul-06 15:09 
AnswerRe: mfc drawing philosophy question - when is the correct time to draw? Pin
Michael Dunn25-Jul-06 16:10
sitebuilderMichael Dunn25-Jul-06 16:10 
GeneralRe: mfc drawing philosophy question - when is the correct time to draw? Pin
charlieg25-Jul-06 16:45
charlieg25-Jul-06 16:45 
GeneralRe: mfc drawing philosophy question - when is the correct time to draw? Pin
Justin Tay25-Jul-06 20:43
Justin Tay25-Jul-06 20:43 
AnswerRe: mfc drawing philosophy question - when is the correct time to draw? [modified] Pin
charlieg26-Jul-06 1:13
charlieg26-Jul-06 1:13 
GeneralRe: mfc drawing philosophy question - when is the correct time to draw? Pin
Justin Tay26-Jul-06 2:22
Justin Tay26-Jul-06 2:22 
GeneralRe: mfc drawing philosophy question - when is the correct time to draw? Pin
charlieg26-Jul-06 3:39
charlieg26-Jul-06 3:39 
GeneralRe: mfc drawing philosophy question - when is the correct time to draw? Pin
charlieg26-Jul-06 4:02
charlieg26-Jul-06 4:02 
GeneralRe: mfc drawing philosophy question - when is the correct time to draw? Pin
Justin Tay26-Jul-06 4:19
Justin Tay26-Jul-06 4:19 
GeneralRe: mfc drawing philosophy question - when is the correct time to draw? Pin
charlieg26-Jul-06 4:24
charlieg26-Jul-06 4:24 
GeneralRe: mfc drawing philosophy question - when is the correct time to draw? Pin
Justin Tay26-Jul-06 4:13
Justin Tay26-Jul-06 4:13 
GeneralRe: mfc drawing philosophy question - when is the correct time to draw? Pin
charlieg26-Jul-06 4:59
charlieg26-Jul-06 4:59 
GeneralRe: mfc drawing philosophy question - when is the correct time to draw? Pin
Justin Tay26-Jul-06 5:34
Justin Tay26-Jul-06 5:34 
QuestionConvert CString to Unsigned short & Vice Versa Pin
JBAK_CP25-Jul-06 13:00
JBAK_CP25-Jul-06 13:00 

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.