openGLのアニメーションを勉強しています。
下のプログラムのどこを変更したら、表示視点が変わりますか?
回答よろしくお願い致します。
#include <stdlib.h>
#include "GL/glut.h"
#include <GL/gl.h>
#include <GL/glu.h>
#include <math.h>
#define KEY_ESC 27
#define PAI 3.1415926536
void polarview(void);
void resetview(void);
unsigned char revolveFlag = GL_FALSE;
unsigned char wireFlag =GL_TRUE;
float xOrig = 0.0,yOrig = 0.0;
float rColor = 1.0, gColor = 1.0, bColor = 1.0;
int xBegin,yBegin;
int mButton;
float distance,twist,elevation,azimuth;
float dist=0.0;
float theta =15.0;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
polarview();
glTranslatef(xOrig,yOrig,-10.0);
glColor3f(rColor,gColor,bColor); if(wireFlag == GL_TRUE) glutWireSphere(1.0,15,15); else glutSolidSphere(1.0,15,15); glPopMatrix(); glutSwapBuffers();
}
void idle(void)
{
theta = fmod(theta+0.5,360.);
glutPostRedisplay();
}
void changeColor(void)
rColor= (float)rand()/RAND_MAX;/*R成分*/ gColor= (float)rand()/RAND_MAX;/*R成分*/ bColor= (float)rand()/RAND_MAX;/*R成分*/
}
void myKbd(unsigned char key, int x, int y)
{
switch(key){
case 'w':
wireFlag = !wireFlag;/
break;
case 'R':
changeColor();
break;
case KEY_ESC:
exit(0);
default:
rColor=1.0;
gColor=1.0;
bColor=1.0;
}
glutPostRedisplay();
}
void myMouse(int button,int state,int x,int y)
{
if(state == GLUT_DOWN){
switch(button){
case GLUT_LEFT_BUTTON:
mButton = button;
break;
case GLUT_RIGHT_BUTTON: mButton = button; break; } xBegin = x; yBegin = y; }
}
void myMotion( int x, int y)
{
int xDisp, yDisp;
xDisp = x- xBegin; yDisp = y -yBegin; switch(mButton){ case GLUT_LEFT_BUTTON: distance +=(float)yDisp/40.0; break; } xBegin = x; yBegin = y; glutPostRedisplay();
}
void mySkey(int key,int x, int y)
{
switch(key){
case GLUT_KEY_LEFT:/左矢印キー/
xOrig -=0.2; if( xOrig <= -2.0) xOrig =-2.0; break; case GLUT_KEY_RIGHT:/*右矢印キー*/ xOrig +=0.2; if( xOrig >= 2.0) xOrig =2.0; break; case GLUT_KEY_UP:/*上矢印キー*/ yOrig +=0.1; if( yOrig>= 2.0) yOrig =2.0; break; case GLUT_KEY_DOWN:/*下矢印キー*/ yOrig -=0.2; if( y<= -2.0) yOrig =-2.0; break; } glutPostRedisplay();
}
void myInit(char *progname)
{
int width=600, height=600;
float aspect =(float)width/(float)height;
glutInitWindowPosition(0,0);
glutInitWindowSize(width,height);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
glutCreateWindow(progname);
glClearColor(0.0,0.0,0.0,1.0);
glutKeyboardFunc(myKbd); glutSpecialFunc(mySkey); glutMouseFunc(myMouse); glutMotionFunc(myMotion); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(30.0,aspect,1.0,20.0); glMatrixMode(GL_MODELVIEW);
}
void resetview(void)
{
distance =5.0;
twist = 0.0;
elevation = 0.0;
azimuth = 0.0;
}
void polarview(void)
{
glTranslatef(0.0,0.0,-distance);
glRotatef(-twist,0.0,0.0,1.0);
glRotatef(-elevation,1.0,0.0,0.0);
glRotatef(-azimuth,0.0,1.0,0.0);
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
myInit(argv[0]);
glutDisplayFunc(display);
glutIdleFunc(NULL);
glutMainLoop();
return(0);
}
回答1件
あなたの回答
tips
プレビュー