コード例 #1
0
ファイル: dao_glut.c プロジェクト: cosim/DaoGraphics
static void GLUT_Render( DaoProcess *proc, DaoValue *p[], int N )
{
	daox_current_renderer = (DaoxRenderer*) p[0];
	daox_current_scene = (DaoxScene*) p[1];
	if( daox_current_renderer->buffer.vertexOffset == 0 ){
		DaoxModel *model = DaoxModel_New();
		DaoxMesh *mesh = DaoxMesh_New();
		DaoxCamera *cam = DaoxRenderer_GetCurrentCamera( daox_current_renderer );
		cam->aspectRatio = window_width / (float) window_height;
		DaoxMesh_MakeViewFrustumCorners( mesh, cam->fovAngle, cam->aspectRatio, cam->nearPlane );
		//DaoxMesh_MakeBoxObject( mesh );
		DaoxMesh_UpdateTree( mesh, 0 );
		DaoxModel_SetMesh( model, mesh );
		DaoxSceneNode_AddChild( (DaoxSceneNode*) cam, (DaoxSceneNode*) model );

		DaoxRenderer_InitShaders( daox_current_renderer );
		DaoxRenderer_InitBuffers( daox_current_renderer );
	}
	glutMainLoop();
}
コード例 #2
0
void Test()
{
	//scene = Test_Collada();

	//DaoVectorGraphics_OnLoad( vmSpace, ns );

	scene = DaoxScene_New();
	camera = DaoxCamera_New();
	renderer = DaoxRenderer_New();

	camera->fovAngle = 30;
	camera->aspectRatio = WIDTH / (float)HEIGHT;

	DaoxModel *model = DaoxModel_New();
	DaoxMesh *mesh = DaoxMesh_New();
	DaoxMesh_MakeViewFrustumCorners( mesh, camera->fovAngle, camera->aspectRatio, camera->nearPlane );
	//DaoxMesh_MakeBoxObject( mesh );
	DaoxMesh_UpdateTree( mesh, 0 );
	DaoxModel_SetMesh( model, mesh );


	//DaoxSceneNode_MoveXYZ( (DaoxSceneNode*) model, 0, 0, -5 );

	DaoxScene_AddNode( scene, (DaoxSceneNode*) camera );
	//DaoxScene_AddNode( scene, (DaoxSceneNode*) model );

	//DaoxSceneNode_MoveXYZ( (DaoxSceneNode*) model, 4.5, 0, 0 );
	//DaoxSceneNode_MoveXYZ( (DaoxSceneNode*) camera, 0, 8, 30 );
	//DaoxCamera_MoveXYZ( camera, 0, 0, 3 );

	DaoxCamera_MoveXYZ( camera, 0, 200, 200 );
	DaoxCamera_LookAtXYZ( camera, 0, 0, 2 );
	camera->farPlane = 1000;
#if 0
#endif

#if 0
	// Grumman-F14:
	DaoxCamera_MoveXYZ( camera, 0, 10, 10 );
	DaoxCamera_LookAtXYZ( camera, 0, 0, 2 );
	camera->farPlane = 1000;
#endif

#if 0
	// MP_US_Engi:
	DaoxCamera_MoveXYZ( camera, 0, -200, 100 );
	DaoxCamera_LookAtXYZ( camera, 0, 100, 100 );
	DaoxCamera_LookAtXYZ( camera, 0, 400, 0 );
	camera->farPlane = 10000;
#endif

	//DaoxScene_Load3DS( scene, "fels.3ds" );
	//DaoxScene_Load3DS( scene, "teapot.3ds" );
	//DaoxScene_Load3DS( scene, "x29.3ds" );
	DaoxScene_Load3DS( scene, "iron-man.3ds" );
	//DaoxScene_Load3DS( scene, "Well/Well.3DS" );
	//DaoxScene_Load3DS( scene, "Grumman-F14-Tomcat/f14d.3ds" );
	//DaoxScene_Load3DS( scene, "MP_US_Engi.3ds" );
	//DaoxScene_Load3DS( scene, "rhino.3ds" );
	//DaoxScene_Load3DS( scene, "burger.3ds" );
	//DaoxScene_Load3DS( scene, "fighter1/fighter1.3ds" );
	//DaoxScene_Load3DS( scene, "cube_with_specular_texture.3DS" );
	//DaoxScene_Load3DS( scene, "cube_with_diffuse_texture.3DS" );

	DaoxMatrix4D rotation = DaoxMatrix4D_EulerRotation( 0.5, 0.3, 0.4 );
	DaoxMatrix4D inverse = DaoxMatrix4D_Inverse( & rotation );
	DaoxMatrix4D prod = DaoxMatrix4D_MulMatrix( & rotation, & inverse );
	DaoxMatrix4D_Print( & rotation );
	DaoxMatrix4D_Print( & inverse );
	DaoxMatrix4D_Print( & prod );

	printf( "nodes: %i\n", scene->nodes->size );


	int j;
	for(j=1; j<0; ++j){
		DaoxModel *model2 = DaoxModel_New();
		DaoxModel_SetMesh( model2, mesh );
		DaoxScene_AddNode( scene, (DaoxSceneNode*) model2 );
		DaoxSceneNode_MoveXYZ( (DaoxSceneNode*) model2, (j+1)*1.5, 0, 0 );
	}
	for(j=1; j<scene->nodes->size; ++j){
		DaoxSceneNode *node = (DaoxSceneNode*) scene->nodes->items.pVoid[j];
		if( node->ctype == daox_type_camera ) camera = (DaoxCamera*) node;
	}
	camera->fovAngle = 60;
	camera->aspectRatio = WIDTH / (float)HEIGHT;

	DaoxSceneNode_AddChild( (DaoxSceneNode*) camera, (DaoxSceneNode*) model );

	DaoxVector3D pos = DaoxSceneNode_GetWorldPosition( (DaoxSceneNode*) camera );
	DaoxVector3D_Print( & pos );


	int i, argc = 1;
	char *argv = "Dao Graphics";

#ifdef FREEGLUT
	glutInitContextVersion (3, 2);
	glutInitContextFlags (GLUT_FORWARD_COMPATIBLE
#ifdef DEBUG
			| GLUT_DEBUG
#endif
	);
#endif

	glutInit(&argc, &argv);
	glutInitWindowSize(WIDTH,HEIGHT);
	glutInitWindowPosition(100,100);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE
#ifndef FREEGLUT
			|GLUT_3_2_CORE_PROFILE
#endif
			);

	glutCreateWindow( argv );
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);


	DaoxRenderer_InitShaders( renderer );
	DaoxRenderer_InitBuffers( renderer );

	glClearColor(0.8f,0.8f,0.8f,1.f);


	glEnable(GL_LIGHTING);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	//glEnable(GL_NORMALIZE);

	//glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);

	glViewport(0, 0, WIDTH, HEIGHT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glLoadIdentity();

	glutGet(GLUT_ELAPSED_TIME);
	glutMainLoop();
}