現在地 >> メニュー >> サンプルコード::OpenGL >> 点のアニメーション >> 点のアニメーション::その2

問題


(0,1)から(1,1)間に30個点をうって、
直線を描画し、アニメーションさせよ。

その他条件:点の太さは3

>>点のアニメーション::その3

答え


#include <cstdio>
#include <GL/glut.h>
#include <GL/glu.h>
#include <GL/gl.h>

void display();
void reshape(int w, int h);
void timer(int value);

void DRAW_XYZ();
void DRAW_POINT();

using namespace std;


inline void GLUT_INIT()
{
glutInitDisplayMode(GLUT_RGBA| GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(200,200);
}

inline void GLUT_CALL_FUNC()
{
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutTimerFunc(10,timer,0);
}

inline void MY_INIT()
{
glClearColor(1.0, 1.0, 1.0, 1.0);
}


int main(int argc, char **argv)
{
glutInit(&argc,argv);
GLUT_INIT();
glutCreateWindow("window name");
GLUT_CALL_FUNC();
MY_INIT();
glutMainLoop();

return 0;
}

/********[ここからコールバック]****************************************/
void display()
{
static int r = 0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

DRAW_XYZ();

glEnable(GL_DEPTH_TEST);

glPushMatrix();
glRotated((double)r, 0.0, 1.0, 0.0);
DRAW_POINT();
glPopMatrix();

glDisable(GL_DEPTH_TEST);

glutSwapBuffers();

r = r + 2;
if(r > 360)
{
r= 0;
}

}


void reshape(int w, int h)
{
glViewport(0, 0, w, h);

glLoadIdentity();
gluPerspective(30.0, (double)w / (double)h, 1.0, 100.0);
gluLookAt(3.0, 4.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}

void timer(int value)
{
glutPostRedisplay();
glutTimerFunc(1,timer,0); //タイマー関数
}


/**********[ここから各種関数]***********************/

void DRAW_XYZ()
{
glBegin(GL_LINES);

glColor3d(0,1,0);//x
glVertex2d(-100,0);
glVertex2d(100, 0);

glColor3d(1,0,0);//y
glVertex2d(0,0);
glVertex2d(0,100);

glColor3d(0,0,1);//z
glVertex3d(0,0,-100);
glVertex3d(0,0, 100);
glEnd();

}

void DRAW_POINT()
{
glPointSize(3);
glBegin(GL_POINTS);

for(int i = 0; i<=29;i++)
{
glVertex2d((double)i/29,1);
}

glEnd();
}

目次

― その他 ―

Wiki内検索

計測中...(07.10.8〜)

Save The World






▲よろしければ広告のクリックもお願いします


▲ランキングに参加しました

管理人/副管理人のみ編集できます