OPENGLのアニメーション(動画)について

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
sueki

OPENGLのアニメーション(動画)について

#1

投稿記事 by sueki » 14年前

以下のソースは、OPENGLとCで作った顔の簡易版です。他のプログラムと併用しているので、不要なもの入っていると思いますが、教えていください。
今、顔や目、口がありますが、顔全体を下に下げて上に上げる。人間で言う頷きのようなアニメーションを作りたいのですが、どこをどう変更すればできますか?教えてください。

コード:

#include <julius/juliuslib.h>
#include <Windows.h>
#include <mmsystem.h>
#include <stdio.h>
#include <stdlib.h>
#include<process.h>
#include<math.h>
#include<glut.h>

double ifx = 0.0;	//
double ify = 0.0;	//
double ifz = 0.0;	//
double ifl = 4.0;	
double ifp = 100;
double ifl1 = 0.0;
double ifl2 = 0.0;
double re = 0.0;
double re2 = 0.0;
double re3 = 0.0;
double re4 = 0.0;
double ax = 0.0;  
double ay = 0.0;  
double az = 0.0;  
double rx = 0.0;  
double ry = 0.0; 
double rz = 0.0;  
double rx2 = 0.0;  
double ry2 = 0.0;  
double rz2 = 0.0;  
double lx = 0.0;  
double ly = 0.0;  
double lz = 0.0;  
double lx2 = 0.0;  
double ly2 = 0.0;  
double lz2 = 0.0; 

double rxA=0.0;
double ryA=0.0;
double rzA=0.0;
double rx2A=0.0;
double ry2A=0.0;
double rz2A=0.0;
double lxA=0.0;
double lyA=0.0;
double lzA=0.0;
double lx2A=0.0;
double ly2A=0.0;
double lz2A=0.0;

GLfloat light[43][4];//口LED配色

void Clip(double e, double e2, double e3, double e4,int ee){
	GLdouble eqn[4] = {e,e2,e3,e4};
	//中央半分をクリッピングする X<0
	if(ee==0){
		glClipPlane(GL_CLIP_PLANE0, eqn);
		glEnable(GL_CLIP_PLANE0);
	}else if(ee==1){
		glClipPlane(GL_CLIP_PLANE1, eqn);
		glEnable(GL_CLIP_PLANE1);
	}else if(ee==2){
		glClipPlane(GL_CLIP_PLANE2, eqn);
		glEnable(GL_CLIP_PLANE2);
	}else if(ee==3){
		glClipPlane(GL_CLIP_PLANE3, eqn);
		glEnable(GL_CLIP_PLANE3);
	}else if(ee==4){
		glClipPlane(GL_CLIP_PLANE4, eqn);
		glEnable(GL_CLIP_PLANE4);
	}

}

//	N角柱(prism)の描画関数
void Draw_Prism ( int N, double len,double h){
	//double  PI = 3.1415926535; // 円周率π
	double  ang = 2.0*PI/N;    // 刻み角度 
	double  x, y;
	double  theta;             // 頂点座標と原点のなす角
	// N角柱をポリゴンで描画   
	// 側面を描画
	glBegin (GL_QUADS) ;
		for( theta = 0.0;theta < 2.0*PI;theta += ang ) {
			x = len*cos( theta );	// x 座標の計算
			y = len*sin( theta );	// y 座標の計算
			glVertex3d( x, y, h );	// 頂点の指定
			glVertex3d( x, y, 0.0 );	// 頂点の指定

			x = len*cos( theta+ang );	// x 座標の計算
			y = len*sin( theta+ang );	// y 座標の計算
			glVertex3d( x, y, 0.0 );	// 頂点の指定
			glVertex3d( x, y, h );		// 頂点の指定
		}
	glEnd();

	// 底面を描画
	glBegin(GL_POLYGON);
		for( theta = 0.0;theta <= 2.0*PI;theta += ang ){
			x = len * cos( theta );		// x 座標の計算
			y = len * sin( theta );		// y 座標の計算
			glVertex3d( x, y, 0.0 );	// 頂点の指定
		}
	glEnd();	

	// 上面を描画
	glBegin( GL_POLYGON );
		for( theta = 0.0;theta <= 2.0*PI;theta += ang ){
			x = len*cos( theta );		// x 座標の計算
			y = len*sin( theta );		// y 座標の計算
			glVertex3d( x, y, h );		// 頂点の指定
		}
	glEnd();	
}

void Model(double e,double e2, double e3, double e4,double x,double y,double z,double rx,double ry,double rz,double rx2,double ry2,double rz2,double lx,double ly,double lz,double lx2,double ly2,double lz2){
	
	Clip(0,0.5,1,1.1,1);
	//顔
	glPushMatrix();
	glTranslatef(0.0,0.0,0.0);
	glRotatef(x-15,1.0,0.0,0.0);
	glRotatef(y,0.0,1.0,0.0);
	glRotatef(z,0.0,0.0,1.0);
	GLfloat c[] = {0.8,0.8,0.8,1};
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, c);
	glutSolidSphere(ifl, ifp, ifp);
	//口//
	glRotatef(15,1.0,0.0,0.0);
	glPushMatrix();
		glRotatef(0,0.0,0.0,1.0);
		glRotatef(-19.5,1.0,0.0,0.0);
		glTranslatef(0.0,ifl+0.01,0.0);
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, light[29]);
		glutSolidSphere(ifl*0.02, 30, 30);
		glPopMatrix();
	
		//右目
		glPushMatrix();
		glRotatef(-23,0.0,0.0,1.0);
		glTranslatef(0.0,ifl-0.3,0.0);
		glRotatef(rx,1.0,0.0,0.0);
		glRotatef(ry,0.0,1.0,0.0);
		glRotatef(rz,0.0,0.0,1.0);
		//強膜(しろ目)
		GLfloat rc[] = {1,1,1,1};
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, rc);
		glutSolidSphere(ifl/5, ifp, ifp);
		glRotatef(23,0.0,0.0,1.0);
		
		
		glDisable(GL_CLIP_PLANE0);
		GLfloat rc3[] = {0,0,0,1};
		//角膜(くろ目)
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, rc3);
		Clip(0,1,0,-ifl/5.2,0);
		glutSolidSphere(ifl/5+0.02, ifp, ifp);
		glDisable(GL_CLIP_PLANE0);
		glPopMatrix();

	
		//左目
		glPushMatrix();
		glRotatef(23,0.0,0.0,1.0);
		glTranslatef(0.0,ifl-0.3,0.0);
		glRotatef(lx,1.0,0.0,0.0);
		glRotatef(ly,0.0,1.0,0.0);
		glRotatef(lz,0.0,0.0,1.0);
		//強膜(しろ目)
		GLfloat lc[] = {1,1,1,1};
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, lc);
		glutSolidSphere(ifl/5, ifp, ifp);
		glRotatef(-23,0.0,0.0,1.0);

		//角膜(くろ目)
		GLfloat lc3[] = {0,0,0,1};
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, lc3);
		Clip(0,1,0,-ifl/5.2,0);
		glutSolidSphere(ifl/5+0.02, ifp, ifp);
		glDisable(GL_CLIP_PLANE0);
		glPopMatrix();
	
	glPopMatrix();
	glDisable(GL_CLIP_PLANE1);
}

// 描画関数
void display( void ){
	//光源の位置
	static GLfloat lightpos[] = {30.0, 40.0, 50.0, 1.0};
	static GLfloat lightpos2[] = {0.0, 40.0, 10.0, 1.0};

	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // カラーバッファとデプスバッファの初期化

	glEnable( GL_DEPTH_TEST ) ; // デプスバッファ(Zバッファ)による前後判定の有効化

	// 図形描画(ここから)
	glLoadIdentity();               // モデルビュー行列の初期化


	gluLookAt ( 0.0, 10.0, 0.0,   0.0, 0.0, 0.0,   0.0, 0.0, 1.0 );
	//光源の位置を設定
	glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
	glLightfv(GL_LIGHT0, GL_POSITION, lightpos2);
	
	
	glRotatef(ifx,1.0,0.0,0.0);
	glRotatef(ify,0.0,1.0,0.0);
	glRotatef(ifz,0.0,0.0,1.0);
	
	Model(re,re2,re3,re4,ax,ay,az,rx,ry,rz,rx2,ry2,rz2,lx,ly,lz,lx2,ly2,lz2);
	
	// 図形描画(ここまで)

	glFlush();
}



// リサイズ関数(引数 w:ウィンドウの幅,h:ウィンドウの高さ)
void resize( int w, int h ) 
{

	glViewport ( 0, 0, w, h ) ;    // ビューポートの設定(この例では開いたウィンドウ全体をビューポートにする.)

	glMatrixMode( GL_PROJECTION ); // 投影変換のための行列モード

	glLoadIdentity ( ) ;           // 変換行列の初期化(単位行列を設定)

	gluPerspective ( 60.0, (double)w/(double)h, 1.0, 20.0 );

	glMatrixMode( GL_MODELVIEW );  // モデリング・ビューイング変換のための行列モード

}


//init関数
void init( void ){
	glClearColor( 0.6, 0.6, 0.9, 1.0 ); //背景色の設定(この例では青色に設定)
	glShadeModel(GL_FLAT);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHT1);
	glEnable(GL_LIGHT2);

}

unsigned __stdcall botthread(void* ppp){
	glutInitWindowSize( 500, 500 ) ;  // ウィンドウサイズの設定(この例では横500,縦500)
	//glutInit( &argc, argv );          // glut機能の初期化
	glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH ); // 表示モードの設定(RGBAカラー+デプスバッファを利用)
	glutCreateWindow( "VHB" );        // ウィンドウの作成
	
	glutDisplayFunc( display );       // 描画関数の指定(この例ではdisplay()関数)
	glutReshapeFunc ( resize );       // リシェープ関数の指定(この例ではresize()関数)
	
	init();                           // init関数の実行
	glutMainLoop( );                  // イベント待ちループ
	return( 0 );
}

void main(){
	HANDLE thread1; 
    HANDLE thread2; 

	thread2 = (HANDLE)_beginthreadex(NULL, 0, botthread, NULL, 0, NULL);

	WaitForSingleObject(thread2, INFINITE); /* スレッドが終了するまで待つ。 */ 
    CloseHandle(thread2); /* ハンドルを閉じる */
    WaitForSingleObject(thread1, INFINITE); /* スレッドが終了するまで待つ。 */ 
    CloseHandle(thread1); /* ハンドルを閉じる */ 

}

ISLe
記事: 2650
登録日時: 15年前
連絡を取る:

Re: OPENGLのアニメーション(動画)について

#2

投稿記事 by ISLe » 14年前

206行目のifxを増減すれば顔が上下に回転しますけど。

閉鎖

“C言語何でも質問掲示板” へ戻る