OpenGlでウィンドウ座標にサイズを固定する方法
2392 ワード
void CModelView::test()//by ZhouZhuo 2014.06.21
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
GLfloat oldcolor[4];
glGetFloatv(GL_CURRENT_COLOR,oldcolor);
GLfloat oldlinewidth;
glGetFloatv(GL_LINE_WIDTH,&oldlinewidth);
int OpenGLVersion[2];
glGetIntegerv(GL_MAJOR_VERSION, &OpenGLVersion[0]);
glGetIntegerv(GL_MINOR_VERSION, &OpenGLVersion[1]);
glLineWidth(2);
int l = glGetError();
if (l == GL_INVALID_VALUE)
{
return;
}
glDisable(GL_LIGHTING);
float delta = 0;
float r = 100;
Pnt3 v;
Pnt3 newv;
GLdouble modelviewM[16];
glGetDoublev(GL_MODELVIEW_MATRIX,modelviewM);
MatX4 M(modelviewM);
M.Transpose();//
MatX4 Mi = M;
Mi.Invert();
GLdouble projectionP[16];
glGetDoublev(GL_PROJECTION_MATRIX,projectionP);
MatX4 P(projectionP);
P.Transpose();
MatX4 Pi = P;
Pi.Invert();
Pnt3 centerinObjectCrood(200,0,0);
float ratio = 0.1*Pi.m[0][0]/r;
Pnt3 center2(0,0,0);
glBegin(GL_LINES);
glColor3f(1,0,0);
glVertex3f(0,0,0);
glVertex3f(500,0,0);
glColor3f(0,1,0);
glVertex3f(0,0,0);
glVertex3f(0,500,0);
glColor3f(0,0,1);
glVertex3f(0,0,0);
glVertex3f(0,0,500);
glEnd();
Pnt4 v4;
Pnt3 yu(0,1,0);
Pnt3 xu(1,0,0);
xu = xu.Normalize();
glBegin(GL_LINE_LOOP);//
glColor3f(1,0,0);
for (int i = 0;i<100;i++)
{
delta += 2*PI/100;
v = xu*3*0.1*sin(delta) + yu*3*0.1*cos(delta);// , , , 1
v4 = Pnt4(v.x,v.y,v.z,1);
//v *= ratio;
v4 = Mi*Pi*v4;
v4 =v4/v4.w;
glVertex3f(v4.x,v4.y,v4.z);
}
glEnd();
yu =Pnt3(0,1,0);
xu =Pnt3(1,0,0);
glBegin(GL_LINE_LOOP);//
glColor3f(0,1,0);
for (int i = 0;i<100;i++)
{
delta += 2*PI/100;
v = xu*2*r*sin(delta) + yu*2*r*cos(delta);
v *= ratio;
v = v ;
newv = Mi*v - Mi*Pnt3(0,0,0)+ centerinObjectCrood;// , (0,0,0) (0,0,0,1),
glVertex3f(newv.x,newv.y,newv.z);
}
glEnd();
yu = Pnt3(0,0.5,1);
xu = Pnt3(1,0,0);
yu = yu.Normalize();
glBegin(GL_LINE_LOOP);
glColor3f(0,0,1);
for (int i = 0;i<100;i++)
{
delta += 2*PI/100;
v = xu*2*r*sin(delta) + yu*2*r*cos(delta);
v *= ratio;
v = v;
newv = Mi*v - Mi*Pnt3(0,0,0) + centerinObjectCrood;
glVertex3f(newv.x,newv.y,newv.z);
}
glEnd();
glEnable(GL_LIGHTING);
glColor4fv(oldcolor);
glLineWidth(oldlinewidth);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}