Jump to content
  • Advertisement
Sign in to follow this  
jinumal

Help me.. I have a little problem..

This topic is 3495 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. I'm beginner... but I have to do this work.. My problem is selection. I tried to find a cause, using "AfxMessageBox" for a week. Maybe, "Picking" do not operate.. Please. help me.. I feel depressed about this. #define BUFSIZE 512 void CTrial3View::OnLButtonDown(UINT nFlags, CPoint point) { _mouse = LBUTTON_DOWN; _mouseDownPoint=point; SetCapture(); if(on_crs) { GLuint selectBuf[BUFSIZE]; GLint viewport[4],hits; int ps_i=1; glGetIntegerv (GL_VIEWPORT, viewport); glSelectBuffer (BUFSIZE, selectBuf); glInitNames(); glPushName(0); glMatrixMode (GL_PROJECTION); glPushMatrix (); glLoadIdentity (); glRenderMode(GL_SELECT); gluPickMatrix((GLdouble) _mouseDownPoint.x,((GLdouble)viewport[3] - (GLdouble) _mouseDownPoint.y), 1.0f, 1.0f, viewport); gluPerspective(45.0f, (GLfloat) (viewport[2]-viewport[0])/(GLfloat) (viewport[3]-viewport[1]), 0.1f, 5000.0f); glMatrixMode(GL_MODELVIEW); CROSSSECTION(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); hits = glRenderMode (GL_RENDER); if (hits>0) { AfxMessageBox("TRUE"); ps_i=0; CCrossSection* tempcrs=GetDocument()->Getcrs(selectBuf[3]); tempcrs->selected=!(tempcrs->selected); if(tempcrs->selected==TRUE) AfxMessageBox("TRUE"); else AfxMessageBox("FALSE"); GetDocument()->Setcrs(selectBuf[3],tempcrs); } } CView::OnLButtonDown(nFlags, point); } BOOL CTrial3View::CROSSSECTION() { CTrial3Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CCrossSection *pCrossSection; int crCoun=pDoc->GetcrsCount(); GLuint crCount=(GLuint)crCoun; glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glPushMatrix(); for(GLuint u=0;u<crCount;u++) { glPushMatrix(); pCrossSection=pDoc->Getcrs(u); if(pCrossSection->selected) glColor4f(0.6,0.25,0.25,0.5); else glColor4f(0.25,0.6,0.6,0.5); glLoadName(u); pCrossSection->Draw(); glPopMatrix(); } glPopMatrix(); return TRUE; } void CCrossSection::Draw() { glTranslatef(0,0,m_zcr); // glutSolidCube(0.5f); } .

Share this post


Link to post
Share on other sites
Advertisement
Can you please clarify your question? Also, please edit your original post and put your code in [source][/source] tags (you can see a list of the available tags here). It really helps make things more readable (right now I'm having a hard time understanding what's what).

Share this post


Link to post
Share on other sites
Sorry.. I'am not proficient in English.

Anyway, I made some parts. And if I click one, color will be changed.

But, color was not changed...

This is my coding.

[/// trial3View.cpp : implementation of the CTrial3View class
//

#include "stdafx.h"
#include "trial3.h"
#include "gl\glut.h"
#include "gl\gl.h"
#include "gl\glu.h"
#include "gl\glaux.h"
#include "trial3Doc.h"
#include "trial3View.h"
#include "pPolygon.h"
#include "CrossSection.h"
#include "MainFrm.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTrial3View

IMPLEMENT_DYNCREATE(CTrial3View, CView)

BEGIN_MESSAGE_MAP(CTrial3View, CView)
//{{AFX_MSG_MAP(CTrial3View)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_SIZE()
ON_WM_ERASEBKGND()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_MOUSEWHEEL()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTrial3View construction/destruction

CTrial3View::CTrial3View() : m_PixelFormat(0), m_hRC(0), m_pDC(0),_mouse(0), _mouseDownPoint(CPoint(0,0)),
_eyeDist(30), _angleHor(45), _angleVer(45), _eyePos(0, 3.8)
{
// TODO: add construction code here

on_crs=FALSE;

}

CTrial3View::~CTrial3View()
{
}

BOOL CTrial3View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style |= ( WS_CLIPCHILDREN | WS_CLIPSIBLINGS );
return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CTrial3View drawing

void CTrial3View::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
ASSERT_VALID(pDoc);

//clear out the color & depth buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();
GLRenderScene();
coordinate();
on_crs=GetDocument()->on_crs;
if((GetDocument()->on_STL)&&(on_crs))
{
CROSSSECTION();
}

glPopMatrix();

//Tell Opengl to flush its pipeline
glFinish();
SwapBuffers(m_pDC->GetSafeHdc());
}

/////////////////////////////////////////////////////////////////////////////
// CTrial3View printing

BOOL CTrial3View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}

void CTrial3View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}

void CTrial3View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CTrial3View diagnostics

#ifdef _DEBUG
void CTrial3View::AssertValid() const
{
CView::AssertValid();
}

void CTrial3View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}

CTrial3Doc* CTrial3View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTrial3Doc)));
return (CTrial3Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTrial3View message handlers

int CTrial3View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;

InitializeOpenGL();
return 0;
}

void CTrial3View::OnDestroy()
{

wglDeleteContext(m_hRC);
if(m_pDC) delete m_pDC;
}

void CTrial3View::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);

if(cy==0) cy=1;
aspect_ratio = (GLdouble)cx/(GLdouble)cy;
if(cx<=0 || cy<=0) return;

glViewport(0, 0, cx, cy);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glnHeight = (GLsizei)cy;
glnWidth = (GLsizei)cx;

gluPerspective(45.0f, aspect_ratio, 0.1f, 5000.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

BOOL CTrial3View::InitializeOpenGL()
{
m_pDC = new CClientDC(this);
if(m_pDC==NULL) return FALSE;

if(!SetupPixelFormat()) return FALSE;
if((m_hRC=::wglCreateContext(m_pDC->GetSafeHdc()))==0) return FALSE;
if (::wglMakeCurrent( m_pDC->GetSafeHdc(), m_hRC )==FALSE) return FALSE;

GLfloat ambLight[] = {0.4f,0.4f,0.4f,1.0f};
GLfloat difLight[] = {0.8f,0.8f,0.8f,1.0f};
GLfloat lightPos[] = {50.0f,50.0f,50.0f,1.0f};

glLightfv(GL_LIGHT0, GL_AMBIENT, ambLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, difLight);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glEnable(GL_LIGHT0);

glEnable(GL_BLEND);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glFrontFace(GL_CCW);
//glEnable(GL_CULL_FACE);

return TRUE;
}


BOOL CTrial3View::SetupPixelFormat()
{
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), //&#54788;&#51116;&#51032; struxture&#51032; &#49324;&#51060;&#51592;&#49444;&#51221;
1, //structure version
PFD_DRAW_TO_WINDOW | //&#50952;&#46020;&#50864;&#50640; &#44536;&#47536;&#45796;.
PFD_SUPPORT_OPENGL | //OPENGL&#54632;&#49688; &#51648;&#50896;
PFD_DOUBLEBUFFER, //&#45908;&#48660; &#48260;&#54140;&#47553;
PFD_TYPE_RGBA, //RGBA &#49353;&#49345;&#47784;&#46300;
24, //24&#48708;&#53944; &#52972;&#47084;&#49324;&#50857;
0,0,0,0,0,0, //not used
0,0,
0,0,0,0,0,
32, //depth&#48260;&#54140; &#49324;&#51060;&#51592;
0,
0,
PFD_MAIN_PLANE, //Main plane&#50640; &#44536;&#47536;&#45796;.
0,
0,0,0
};

if((m_PixelFormat=ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd)) == 0)
{
return FALSE;
}

if (::SetPixelFormat(m_pDC->GetSafeHdc(), m_PixelFormat, &pfd)==FALSE)
{
return FALSE;
}

return TRUE;
}


BOOL CTrial3View::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return TRUE;
}


#define BUFSIZE 512
void CTrial3View::OnLButtonDown(UINT nFlags, CPoint point)
{
_mouse = LBUTTON_DOWN;
_mouseDownPoint=point;
SetCapture();
/* if(on_crs){
if(ProcessSelection(point)!=0)
{ _mouse = LBUTTON_DOWN;
_mouseDownPoint=point;
SetCapture();
}
}*/

// else{

if(on_crs)
{ GLuint selectBuf[BUFSIZE];
GLint viewport[4],hits;
int ps_i=1;
glGetIntegerv (GL_VIEWPORT, viewport);
glSelectBuffer (BUFSIZE, selectBuf);
glInitNames();
glPushName(0);
glMatrixMode (GL_PROJECTION);
glPushMatrix ();
glLoadIdentity ();
glRenderMode(GL_SELECT);
gluPickMatrix((GLdouble) _mouseDownPoint.x,((GLdouble)viewport[3] - (GLdouble) _mouseDownPoint.y), 1.0f, 1.0f, viewport);
gluPerspective(45.0f, (GLfloat) (viewport[2]-viewport[0])/(GLfloat) (viewport[3]-viewport[1]), 0.1f, 5000.0f);
glMatrixMode(GL_MODELVIEW);
CROSSSECTION();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
hits = glRenderMode (GL_RENDER);
// AfxMessageBox("asd");
/* int hit=(int)hits;
CString adad;
adad.Format("%d",hit);
AfxMessageBox(adad);*/


if (hits>0)
{AfxMessageBox("TRUE");
ps_i=0;

CCrossSection* tempcrs=GetDocument()->Getcrs(selectBuf[3]);
tempcrs->selected=!(tempcrs->selected);
if(tempcrs->selected==TRUE)
AfxMessageBox("TRUE");
else
AfxMessageBox("FALSE");
GetDocument()->Setcrs(selectBuf[3],tempcrs);
}
}



CView::OnLButtonDown(nFlags, point);

}
BOOL CTrial3View::CROSSSECTION()
{
CTrial3Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

CCrossSection *pCrossSection;
int crCoun=pDoc->GetcrsCount();
GLuint crCount=(GLuint)crCoun;

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
// glColor4f(0.6,0.25,0.25,0.5);
// glMatrixMode(GL_MODELVIEW);
glPushMatrix();

for(GLuint u=0;u<crCount;u++)
{
glPushMatrix();
pCrossSection=pDoc->Getcrs(u);

if(pCrossSection->selected) glColor4f(0.6,0.25,0.25,0.5);
else glColor4f(0.25,0.6,0.6,0.5);
glLoadName(u+1);
pCrossSection->Draw();
glPopMatrix();
}
glPopMatrix();
// MessageBox("hi");
// glutSwapBuffers();
return TRUE;
}



void CTrial3View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

_mouseDownPoint=CPoint(0, 0);
ReleaseCapture();
_mouse = BUTTON_UP;
CView::OnLButtonUp(nFlags, point);

}

void CTrial3View::OnMouseMove(UINT nFlags, CPoint point)
{

if (GetCapture()==this) {
if (_mouse == LBUTTON_DOWN) {
//Increment the object rotation angles
_angleHor+=(point.x-_mouseDownPoint.x)/2;
_angleVer+=(point.y-_mouseDownPoint.y)/2;
}
else if (_mouse == RBUTTON_DOWN) {
_eyePos.x -= (point.x-_mouseDownPoint.x)/50.;
_eyePos.y += (point.y-_mouseDownPoint.y)/50.;
}
InvalidateRect(NULL,FALSE);
_mouseDownPoint=point;
}
CView::OnMouseMove(nFlags, point);
}

BOOL CTrial3View::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
// TODO: Add your message handler code here and/or call default
_eyeDist += (zDelta < 0) ? 1.5 : -1.5;
InvalidateRect(NULL,FALSE);
return CView::OnMouseWheel(nFlags, zDelta, pt);
}

void CTrial3View::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
_mouse = RBUTTON_DOWN;
_mouseDownPoint=point;
SetCapture();
CView::OnRButtonDown(nFlags, point);

}


void CTrial3View::OnRButtonUp(UINT nFlags, CPoint point)
{
_mouseDownPoint=CPoint(0, 0);
ReleaseCapture();
_mouse = BUTTON_UP;

CView::OnRButtonUp(nFlags, point);
}

void CTrial3View::coordinate()
{
glDisable(GL_LIGHTING);
glLineWidth(2.0f);
glBegin(GL_LINES);
// The Z-axis
glColor3d(0., 0., 1.);
glVertex3d(0., 0., 0.);
glVertex3d(0., 0., 0.5);

// The Y-axis
glColor3d(0., 1., 0.);
glVertex3d(0., 0., 0.);
glVertex3d(0., 0.5, 0.);

// The X-axis
glColor3d(1., 0., 0.);
glVertex3d(0., 0., 0.);
glVertex3d(0.5, 0., 0.);
glEnd();
glEnable(GL_LIGHTING);
}

void CTrial3View::GLRenderScene()
{
CTrial3Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

gluLookAt( _eyeDist, 0, 1.4, 0, _eyePos.x, _eyePos.y, 0,0,1 );

glRotated( _angleVer, 0,1,0 );

glRotated( _angleHor, 0,0,1 );

int plcount = pDoc->getsize();
glPushMatrix();

glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glColor3f(0.0f,1.0f,0.0f);
glBegin(GL_TRIANGLES);
int plPos;
CpPolygon *lptPoly;
if(plcount)
{

for(plPos=0;plPos<plcount;plPos++)
{
lptPoly=pDoc->getpoly(plPos);
lptPoly->GLRendering();
}
}


glEnd();
glPopMatrix();
}
]
[/// trial3Doc.cpp : implementation of the CTrial3Doc class
//

#include "stdafx.h"
#include "trial3.h"
#include "trial3Doc.h"
#include<fstream>
#include "pPolygon.h"
#include "MainFrm.h"
#include "pPolygon.h"
#include "CrossSection.h"
#include "Point3d.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTrial3Doc
IMPLEMENT_DYNCREATE(CTrial3Doc, CDocument)

BEGIN_MESSAGE_MAP(CTrial3Doc, CDocument)
//{{AFX_MSG_MAP(CTrial3Doc)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
ON_COMMAND(IDD_CROSSSECTION, OnCrosssection)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTrial3Doc construction/destruction

using namespace std;

CTrial3Doc::CTrial3Doc() : left(1000000), right(-1000000), top(-1000000), bottom(1000000),premax_point(-1000000),premin_point(1000000)
{
// TODO: add one-time construction code here
// STLData();
on_crs=FALSE;
on_STL=FALSE;
}

CTrial3Doc::~CTrial3Doc()
{
}

BOOL CTrial3Doc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;

// TODO: add reinitialization code here
// (SDI documents will reuse this document)

return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CTrial3Doc serialization

void CTrial3Doc::Serialize(CArchive& ar)
{

}

/////////////////////////////////////////////////////////////////////////////
// CTrial3Doc diagnostics

#ifdef _DEBUG
void CTrial3Doc::AssertValid() const
{
CDocument::AssertValid();
}

void CTrial3Doc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTrial3Doc commands

void CTrial3Doc::STLData(CString &file)
{
char* filename = LPSTR(LPCTSTR(file));
char ch,cha='b';
int q=0;
CPoint3d norm_vec,point1,point2,point3;
if(!on_STL){
ifstream fin(filename);
while(fin.get(ch))
{
if((cha=='a')&&(ch=='l')){
fin>>norm_vec.m_x>>norm_vec.m_y>>norm_vec.m_z;
}
else if((cha=='e')&&(ch=='x')&&(q==0))
{
fin>>point1.m_x>>point1.m_y>>point1.m_z;
q++;
}
else if((cha=='e')&&(ch=='x')&&(q==1))
{
fin>>point2.m_x>>point2.m_y>>point2.m_z;
q++;
}
else if((cha=='e')&&(ch=='x')&&(q==2))
{
fin>>point3.m_x>>point3.m_y>>point3.m_z;

CpPolygon *ppPolygon=AddPoly(norm_vec,point1,point2,point3);
q=0;
Side(point1.m_x,point2.m_x,point3.m_x,point1.m_y,point2.m_y,point3.m_y);

max_point=MaxPoint(point1.m_z,point2.m_z,point3.m_z);
min_point=MinPoint(point1.m_z,point2.m_z,point3.m_z);

if(premin_point>min_point)
premin_point=min_point;
if(premax_point<max_point)
premax_point=max_point;
}
else if((cha=='d')&&(ch=='s')){
on_STL=TRUE;
}


cha=ch;

}
fin.close();
}

}

int CTrial3Doc::getsize()
{
return m_polygon.GetSize();
}

CpPolygon* CTrial3Doc::getpoly(int nIndex)
{
return (CpPolygon*) m_polygon[nIndex];
}

CpPolygon* CTrial3Doc::AddPoly(CPoint3d t_norm_vec, CPoint3d t_point1, CPoint3d t_point2, CPoint3d t_point3)
{
CpPolygon *ppPolygon = new CpPolygon(t_norm_vec,t_point1,t_point2,t_point3);
try
{
m_polygon.Add(ppPolygon);
}
catch(CMemoryException* perr)
{
AfxMessageBox("Out of memory",MB_ICONSTOP|MB_OK);
if(ppPolygon)
{
delete ppPolygon;
ppPolygon=NULL;
}
perr->Delete();
}
return ppPolygon;
}


void CTrial3Doc::DeleteContents()
{
// TODO: Add your specialized code here and/or call the base class
int liCount=m_polygon.GetSize();
int liPos;

if(liCount)
{
for(liPos=0 ; liPos<liCount; liPos++)
delete m_polygon[liPos];

m_polygon.RemoveAll();
}
int crCount=m_oacrs.GetSize();
int crsPos;

if(crCount)
{
for(crsPos=0; crsPos<crCount; crsPos++)
delete m_oacrs[crsPos];

m_oacrs.RemoveAll();
}

CDocument::DeleteContents();
}



void CTrial3Doc::OnFileOpen()
{
// TODO: Add your command handler code here
char Filter[] = "STL File(*.stl) |*.stl|&#47784;&#46304;&#54028;&#51068;(*.*)|*.*|";
CFileDialog fileDlg(TRUE, "stl file(*.stl)", "*.stl", OFN_HIDEREADONLY |
OFN_FILEMUSTEXIST, Filter, NULL);

if(fileDlg.DoModal()==IDOK){
CString file=fileDlg.GetPathName();

STLData(file);
}
}

void CTrial3Doc::OnFileSave()
{
// TODO: Add your command handler code here

char Filter[] = "STL File(*.stl) |*.stl|&#47784;&#46304;&#54028;&#51068;(*.*)|*.*|";
CFileDialog fileDlg(FALSE, "stl file(*.stl)", "*.stl", OFN_HIDEREADONLY |
OFN_FILEMUSTEXIST, Filter, NULL);

if(fileDlg.DoModal()==IDOK){
CString file=fileDlg.GetPathName();

STLSave(file);
}

}

void CTrial3Doc::STLSave(CString &file)
{
char* filename = LPSTR(LPCTSTR(file));
ofstream fout(filename);
CpPolygon *svPoly;
int plPos;
int plcount = getsize();
fout<<"solid ascii"<<endl;

for(plPos=0;plPos<plcount;plPos++)
{
svPoly=getpoly(plPos);
fout<<" facet normal "<<svPoly->m_norm_vec.m_x<<" "<<svPoly->m_norm_vec.m_y<<" "<<svPoly->m_norm_vec.m_z<<endl;
fout<<" outer loop"<<endl;
fout<<" vertex "<<svPoly->m_point1.m_x<<" "<<svPoly->m_point1.m_y<<" "<<svPoly->m_point1.m_z<<endl;
fout<<" vertex "<<svPoly->m_point2.m_x<<" "<<svPoly->m_point2.m_y<<" "<<svPoly->m_point2.m_z<<endl;
fout<<" vertex "<<svPoly->m_point3.m_x<<" "<<svPoly->m_point3.m_y<<" "<<svPoly->m_point3.m_z<<endl;
fout<<" endloop"<<endl;
fout<<" endfacet"<<endl;
}
fout<<"endsolid"<<endl;
fout.close();
}
float CTrial3Doc::MinPoint(float &z1, float &z2, float &z3)
{
if(z1>z2){
if(z2>z3)
return z3;
else
return z2;}
else{
if(z1>z3)
return z3;
else
return z1;
}
}



void CTrial3Doc::Side(float &x1, float &x2, float &x3, float &y1, float &y2, float &y3)
{
// if(((left+0.1)>x3)||((bottom+0.1)>y3)||((right-0.1)<x3)||((top-0.1)<y3)){
float templeft=MinPoint(x1,x2,x3);
float tempbottom=MinPoint(y1,y2,y3);
float tempright=MaxPoint(x1,x2,x3);
float temptop=MaxPoint(y1,y2,y3);
if(left>templeft)
left=templeft;
if(bottom>tempbottom)
bottom=tempbottom;
if(right<tempright)
right=tempright;
if(top<temptop)
top=temptop;
// }
}

float CTrial3Doc::MaxPoint(float &z1, float &z2, float &z3)
{
if(z1<z2){
if(z2<z3)
return z3;
else
return z2;}
else{
if(z1<z3)
return z3;
else
return z1;
}
}

CCrossSection* CTrial3Doc::Addcrs(float t_zcr)
{
CCrossSection *pCrossSection = new CCrossSection(top,right,left,bottom,t_zcr);
try
{
m_oacrs.Add(pCrossSection);
SetModifiedFlag();
}
catch(CMemoryException* perr)
{
AfxMessageBox("Out of memory",MB_ICONSTOP|MB_OK);
if(pCrossSection)
{
delete pCrossSection;
pCrossSection=NULL;
}
perr->Delete();
}
return pCrossSection;
}


int CTrial3Doc::GetcrsCount()
{
return m_oacrs.GetSize();
}


CCrossSection* CTrial3Doc::Getcrs(int nIndex)
{
return (CCrossSection*)m_oacrs[nIndex];
}

void CTrial3Doc::Setcrs(int nIndex, CCrossSection *newElement)
{
m_oacrs.SetAt(nIndex,newElement);
}

void CTrial3Doc::Get_crs(float thickness)
{

float uu,zcr=-1000000;
for(int u=1;zcr<(premax_point-0.5*thickness);u++)
{
uu=(float)u;
zcr=thickness*(uu-0.5)+premin_point;
CCrossSection* pCrossSection=Addcrs(zcr);
}
}

void CTrial3Doc::OnCrosssection()
{
// TODO: Add your command handler code here
if(m_thick.DoModal()==IDOK)
{
// UpdateData(TRUE);
float thick=m_thick.m_thickness;
Get_crs(thick);
on_crs=TRUE;
}

}
]
[/// CrossSection.cpp: implementation of the CCrossSection class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "trial3.h"
#include "CrossSection.h"
#include "gl\glut.h"
#include "gl\gl.h"
#include "gl\glu.h"
#include "gl\glaux.h"
#include "trial3Doc.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CCrossSection::CCrossSection()
{
// selected=0;
}

CCrossSection::~CCrossSection()
{

}

CCrossSection::CCrossSection(float top, float right, float left, float bottom,float zcr)
{
m_top=top;
m_right=right;
m_left=left;
m_bottom=bottom;
m_zcr=zcr;
selected=0;
}

/*GLfloat red[]={ 1.0,0.0,0.0,0.5};
GLfloat blue[]={ 0.0,0.0,1.0,0.5};*/



void CCrossSection::Draw()
{
/* GLfloat red[]={ 1.0f ,0.0f ,0.0f ,0.5f };
GLfloat blue[]={ 0.0f ,0.0f ,1.0f ,0.5f };

if (selected) {
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,blue);
}
else {
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,blue);
}*/

/* glMatrixMode(GL_MODELVIEW);
glLoadIdentity();*/

glTranslatef(0,0,m_zcr);
//glRectf(m_left,m_top,m_right,m_bottom);
glutSolidCube(0.5f);
/* int uuu=selected;
CString adad;
adad.Format("%d",uuu);
AfxMessageBox(adad);*/



/*glBegin(GL_QUADS);
glVertex3f(m_left,m_bottom,m_zcr);
glVertex3f(m_left,m_top,m_zcr);
glVertex3f(m_right,m_top,m_zcr);
glVertex3f(m_right,m_bottom,m_zcr);
glEnd();*/


}
]

Share this post


Link to post
Share on other sites
Quote:
Original post by jinumal
Sorry.. I'am not proficient in English.

Anyway, I made some parts. And if I click one, color will be changed.

But, color was not changed...

That's ok if you aren't great at English. But really, you haven't asked a question. You haven't said what's wrong (you said "My problem is selection," but what's your problem?). It would really help everyone out if you could tell us all in greater detail what you are having problems with, what you want to accomplish, and what you've tried. And don't worry if you don't know how to say it all perfectly in English.

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!