前提・実現したいこと
OpenGL でNURBS 曲面を作成しております.
合計16点の制御点での実装はできたのですが,それ以上制御点数を
増やすとエラーは出ないのですが,描画結果が表示されません.
どのような原因が考えられるでしょうか.
回答お待ちしております.
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>
GLfloat ctlpoints[6][6][3] = {
{{0,0,0},
{0,0.33,0},
{0,0.66,0},
{0,1,0}},
{{6,0,2},
{6,0.33,2},
{6,0.66,2},
{6,1,2}},
{{3,0,4},
{3,0.33,4},
{3,0.66,4},
{3,1,4}},
{{0,0,4},
{0,0.33,4},
{0,0.66,4},
{0,1,4}},
{{-3,2,2},
{-3,2.33,2},
{-3,2.66,2},
{-3,3,2}},
{{3,2,0},
{3,2.33,0},
{3,2.66,0},
{3,3,0}}
};
int showPoints = 0;
GLfloat knotu[8] = { 0,0,0,0,1,1,1,1 };
GLfloat knotv[8] = { 0,0,0,0,1,1,1,1 };
GLUnurbsObj* theNurb;
void init(void)
{
GLfloat mat_diffuse[] = { 0.7, 0.7, 0.7, 1.0 };
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 100.0 };
glClearColor(1.0, 1.0, 1.0, 1.0); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glEnable(GL_AUTO_NORMAL); /* 法線の計算 */ glEnable(GL_NORMALIZE); /* 正規化 */ theNurb = gluNewNurbsRenderer(); /* NURBS オブジェクトを作成 */ gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 100.0); gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL);
}
double xAngle = 0.0, yAngle = 0.0;
void display(void)
{
int i, j;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotated(xAngle, 1, 0, 0); glRotated(yAngle, 0, 1, 0); glScalef(0.5, 0.5, 0.5); gluBeginSurface(theNurb); gluNurbsSurface(theNurb, 10, knotu, 10, knotv, 4 * 3, 3, &ctlpoints[0][0][0], 6,4, GL_MAP2_VERTEX_3); gluEndSurface(theNurb); if (showPoints) { glPointSize(5.0); glDisable(GL_LIGHTING); glColor3f(1.0, 0.0, 0.0); glBegin(GL_POINTS); for (i = 0; i < 6; i++) for (j = 0; j < 4; j++) glVertex3f(ctlpoints[i][j][0], ctlpoints[i][j][1], ctlpoints[i][j][2]); glEnd(); glEnable(GL_LIGHTING); } glPopMatrix(); glFlush();
}
void resize(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (GLdouble)w / (GLdouble)h, 3.0, 8.0);
glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 0.0, -5.0);
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 'c':
case 'C':
showPoints = !showPoints;
glutPostRedisplay();
break;
case '\33':
case 'q':
case 'Q':
exit(0);
break;
default:
break;
}
}
int xStart, yStart;
bool mouseFlag = GL_FALSE;
void myMouseFunc(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
xStart = x;
yStart = y;
mouseFlag = GL_TRUE;
}
else
{
mouseFlag = GL_FALSE;
}
}
void myMouseMotion(int x, int y)
{
int xdis, ydis;
double a = 0.5;
if (mouseFlag == GL_FALSE)return; xdis = x - xStart; ydis = y - yStart; xAngle += (double)ydis * a; yAngle += (double)xdis * a; xStart = x; yStart = y; glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow(argv[0]);
init();
glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(myMouseFunc);
glutMotionFunc(myMouseMotion);
glutMainLoop();
return 0;
}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/12/09 03:22