3DBezierSurface.cpp
资源名称:Jhy3D.rar [点击查看]
上传用户:eehhbb
上传日期:2022-08-03
资源大小:2550k
文件大小:3k
源码类别:
OpenGL
开发平台:
Visual C++
- // 3DBezierSurface.cpp: implementation of the C3DBezierSurface class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "jhy3d.h"
- #include "3DBezierSurface.h"
- #include "Material.h"
- #include "Vector3.h"
- #include "glglut.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- C3DBezierSurface::C3DBezierSurface()
- {
- m_position.m_x = m_position.m_y = m_position.m_z = 0.0f;
- m_pCtrlPoints = NULL;
- m_nNumOFVCtrl = m_nNumOFUCtrl = 0;
- }
- C3DBezierSurface::~C3DBezierSurface()
- {
- }
- void C3DBezierSurface::DestroyBezierSurface()
- {
- if(m_pCtrlPoints)
- {
- delete[] m_pCtrlPoints;
- m_pCtrlPoints = NULL;
- }
- }
- void C3DBezierSurface::DefaultBezierSuf()
- {
- if(m_pCtrlPoints)
- {
- DestroyBezierSurface();
- }
- m_nNumOFVCtrl = m_nNumOFUCtrl = 4;
- m_pCtrlPoints = new float[m_nNumOFUCtrl*m_nNumOFVCtrl*3];
- m_pCtrlPoints[0] = -0.1875; m_pCtrlPoints[1] = -0.1875; m_pCtrlPoints[2] = 0.5;
- m_pCtrlPoints[3] = -0.0625; m_pCtrlPoints[4] = -0.1875; m_pCtrlPoints[5] = 0.25;
- m_pCtrlPoints[6] = 0.0625; m_pCtrlPoints[7] = -0.1875; m_pCtrlPoints[8] = -0.125;
- m_pCtrlPoints[9] = 0.1875; m_pCtrlPoints[10] = -0.1875;m_pCtrlPoints[11] = 0.25;
- m_pCtrlPoints[12] = -0.1875;m_pCtrlPoints[13]=-0.0625; m_pCtrlPoints[14] = 0.125;
- m_pCtrlPoints[15] = -0.0625;m_pCtrlPoints[16]=-0.0625; m_pCtrlPoints[17]=0.375;
- m_pCtrlPoints[18]=0.0625; m_pCtrlPoints[19]=-0.0625; m_pCtrlPoints[20]=0.0;
- m_pCtrlPoints[21]=0.1875; m_pCtrlPoints[22]=-0.0625; m_pCtrlPoints[23]=-0.125;
- m_pCtrlPoints[24]=-0.1875; m_pCtrlPoints[25]=0.0625; m_pCtrlPoints[26]= 0.5;
- m_pCtrlPoints[27]=-0.0625; m_pCtrlPoints[28]=0.0625; m_pCtrlPoints[29]=0.0;
- m_pCtrlPoints[30]=0.0625; m_pCtrlPoints[31]=0.0625; m_pCtrlPoints[32]=0.375;
- m_pCtrlPoints[33]=0.1875; m_pCtrlPoints[34]=0.0625; m_pCtrlPoints[35]=0.5;
- m_pCtrlPoints[36]=-0.1875; m_pCtrlPoints[37]=0.1875; m_pCtrlPoints[38]=-0.25;
- m_pCtrlPoints[39]=-0.0625; m_pCtrlPoints[40]=0.1875; m_pCtrlPoints[41]=-0.25;
- m_pCtrlPoints[42]=0.0625; m_pCtrlPoints[43]=0.1875; m_pCtrlPoints[44]=0.0;
- m_pCtrlPoints[45]=0.1875; m_pCtrlPoints[46]=0.1875; m_pCtrlPoints[47]=-0.125;
- }
- void C3DBezierSurface::RenderTextureSolidBeizerSurface()
- {
- if(m_pCtrlPoints == NULL)
- return;
- float sTexCoords[2][2][2] = {{{0.0,0.0},{0.0,1.0}},{{1.0,1.0}}};
- glEnable(GL_MAP2_VERTEX_3);
- glEnable(GL_MAP2_TEXTURE_COORD_2);
- glEnable(GL_AUTO_NORMAL);
- glEnable(GL_NORMALIZE);
- glMaterialfv(GL_FRONT,GL_AMBIENT,m_matBezier.m_vAmbient);
- glMaterialfv(GL_FRONT,GL_DIFFUSE,m_matBezier.m_vDiffuse);
- glMaterialfv(GL_FRONT,GL_SPECULAR,m_matBezier.m_vSpecular);
- glMaterialf(GL_FRONT,GL_SHININESS,m_matBezier.m_vShininess);
- glMaterialfv(GL_FRONT,GL_EMISSION,m_matBezier.m_vEmission);
- glPushMatrix();
- glTranslatef(m_position.m_x,m_position.m_y,m_position.m_z);
- glMap2f(GL_MAP2_VERTEX_3,0,1,3,m_nNumOFUCtrl,0,1,m_nNumOFUCtrl * 3,m_nNumOFVCtrl,m_pCtrlPoints);
- glMap2f(GL_MAP2_TEXTURE_COORD_2,0,1,2,2,0,1,4,2,&sTexCoords[0][0][0]);
- glMapGrid2f(20,0,1,20,0,1);
- glEvalMesh2(GL_FILL,0,20,0,20);
- glPopMatrix();
- glDisable(GL_AUTO_NORMAL);
- glDisable(GL_NORMALIZE);
- }