第9章课后习题参考答案

更新时间:2023-05-08 07:48:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

第九章习题参考答案

1.基于Turbo C环境进行动画编程可以采用哪些方法?

(1)全局画擦画:cleardevice( )

(2)局部画擦画:getimage( ) putimage( )

(3)页切换:setactivepage( ) setvisualpage( )

(4)延时: delay( )

(5)函数式

(6)图形变换

2.简要说说你对OpenGL及OGRE的认识?

(1)GL是美国SGI公司为图形工作站开发的一种功能强大的三维图形机制,经过长期发展,在跨平台移植的过程中,由GL扩充形成了OpenGL,目前,它已经成为高性能图形和交互式视景处理的工业标准。有了OpenGL的帮助,编程者可以轻松地进行三维动画的程序设计。

OpenGL提供的相关库有:

1)OpenGL核心库(GL)

2)OpenGL实用库(GLU)

3)OpenGL辅助库(GLAUX)

4)OpenGL工具库(GLUT)

5)OpenGL对窗口系统的扩展(WGL,等等)

对于各个库,函数功能可分为两大类:渲染功能,提供图形绘制所需的各种功能函数;窗口管理功能,管理窗口系统的所有相关功能,如键盘鼠标的响应,各种窗口事件等等。

(2)OGRE(Object-oriented Graphics Rendering Engine,面向对象的图形渲染引擎)是国际上知名的开源图形渲染引擎。OGRE是用C++开发的面向对象且使用灵活的3D引擎,它的目的是让编程者能更容易开发基于3D的动画或游戏等应用程序。引擎中的类库对更底层的系统库(如OpenGL或Direct3D)的全部使用细节进行了简化封装和抽象,同时提供基于现实世界的对象接口以及其它非常有用的工具类。因此,利用OGRE引擎来进行动画编程可以提高开发的效率,并且一般情况下要比基于OpenGL的动画编程还简单些。

3.基于Turbo C环境编写模拟自由落体的动画。

#include

#include

#define g 10

main()

{int x=320,y,t;

int gdriver=DETECT,gmode;

initgraph(&gdriver,&gmode,"");

cleardevice();

setcolor(15);

do{

for(t=0;t<10;t++)

{y=0.5*g*t*t;

circle(x,y,20);

delay(50000);

cleardevice();

}

for(t=0;t<10;t++)

{y=405-(90*t-0.5*g*t*t);

circle(x,y,20);

delay(50000);

cleardevice();

}

}while(!kbhit());

closegraph();

}

4.编写基于OpenGL图形库的Visual C++程序,内容为旋转一茶壶的三维动画。

#include

#include

#include

static float rot = 0.0f;

void init(void)

{

glClearColor(0.0, 0.0, 0.0, 0.0);

glShadeModel(GL_SMOOTH);

glEnable(GL_DEPTH_TEST);

}

void display(void)

{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

gluLookAt(0.0f, 1.5f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

glBegin(GL_QUADS);

glColor3f(1.0f, 0.0f, 0.0f);

glNormal3f( 0.0f, 1.0f, 0.0f);

glVertex3f(-2.5f, -0.75f, 2.5f);

glVertex3f(2.5f, -0.75f, 2.5f);

glVertex3f(2.5f, -0.75f, -2.5f);

glVertex3f(-2.5f, -0.75f, -2.5f);

glEnd();

glRotatef(rot, 0.0f, 1.0f, 0.0f);

glColor3f(1.0f, 1.0f, 1.0f);

glutSolidTeapot(1.0f);

rot += 0.1f;

glutSwapBuffers();

}

void reshape (int width, int height)

{

glViewport(0, 0, width, height);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 100.0f);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

}

void keyboard(unsigned char key, int x, int y)

{

switch (key)

{

case 27:

exit(0);

break;

case 'p':

break;

default:

break;

}

}

int main(int argc, char** argv)

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

glutInitWindowSize(640, 480);

glutInitWindowPosition(100, 100);

glutCreateWindow("Rotate");

init();

glutDisplayFunc(display);

glutReshapeFunc(reshape);

glutKeyboardFunc(keyboard);

glutIdleFunc(display);

glutMainLoop();

return 0;

}

5.编写基于OGRE引擎的Visual C++程序,内容为一9行9列的机器人阵列。

#include

#include

#include "ExampleApplication.h"

class SelectionRectangle : public ManualObject

{

public:

SelectionRectangle(const String &name)

: ManualObject(name)

{

setRenderQueueGroup(RENDER_QUEUE_OVERLAY);

setUseIdentityProjection(true);

setUseIdentityView(true);

setQueryFlags(0);

}

void setCorners(float left, float top, float right, float bottom)

{

left = left * 2 - 1;

right = right * 2 - 1;

top = 1 - top * 2;

bottom = 1 - bottom * 2;

clear();

begin("", RenderOperation::OT_LINE_STRIP);

position(left, top, -1);

position(right, top, -1);

position(right, bottom, -1);

position(left, bottom, -1);

position(left, top, -1);

end();

AxisAlignedBox box;

box.setInfinite();

setBoundingBox(box);

}

void setCorners(const Vector2 &topLeft, const Vector2 &bottomRight)

{

setCorners(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y);

}

};

class DemoListener : public ExampleFrameListener, public OIS::MouseListener

{

public:

DemoListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager) : ExampleFrameListener(win, cam, false, true), mSceneMgr(sceneManager), mSelecting(false)

{

mRect = new SelectionRectangle("Selection SelectionRectangle");

mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(mRect);

mVolQuery =

mSceneMgr->createPlaneBoundedVolumeQuery(PlaneBoundedVolumeList());

mMouse->setEventCallback(this);

} // DemoListener

~DemoListener()

{

mSceneMgr->destroyQuery(mVolQuery);

delete mRect;

}

bool mouseMoved(const OIS::MouseEvent &arg)

{

CEGUI::System::getSingleton().injectMouseMove(arg.state.X.rel, arg.state.Y.rel);

if (mSelecting)

{

CEGUI::MouseCursor *mouse = CEGUI::MouseCursor::getSingletonPtr();

mStop.x = mouse->getPosition().d_x / (float)arg.state.width;

mStop.y = mouse->getPosition().d_y / (float)arg.state.height;

mRect->setCorners(mStart, mStop);

}

return true;

}

bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)

{

if (id == OIS::MB_Left)

{

CEGUI::MouseCursor *mouse = CEGUI::MouseCursor::getSingletonPtr();

mStart.x = mouse->getPosition().d_x / (float)arg.state.width;

mStart.y = mouse->getPosition().d_y / (float)arg.state.height;

mStop = mStart;

mSelecting = true;

mRect->clear();

mRect->setVisible(true);

}

return true;

}

bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id)

{

if (id == OIS::MB_Left)

{

performSelection(mStart, mStop);

mSelecting = false;

mRect->setVisible(false);

}

return true;

}

void performSelection(const Vector2 &first, const Vector2 &second)

{

float left = first.x, right = second.x,

top = first.y, bottom = second.y;

if (left > right)

swap(left, right);

if (top > bottom)

swap(top, bottom);

if ((right - left) * (bottom - top) < 0.0001)

return;

Ray topLeft = mCamera->getCameraToViewportRay(left, top);

Ray topRight = mCamera->getCameraToViewportRay(right, top);

Ray bottomLeft = mCamera->getCameraToViewportRay(left, bottom);

Ray bottomRight = mCamera->getCameraToViewportRay(right, bottom);

PlaneBoundedVolume vol;

vol.planes.push_back(Plane(topLeft.getPoint(3), topRight.getPoint(3), bottomRight.getPoint(3)));

vol.planes.push_back(Plane(topLeft.getOrigin(), topLeft.getPoint(100), topRight.getPoint(100)));

vol.planes.push_back(Plane(topLeft.getOrigin(), bottomLeft.getPoint(100), topLeft.getPoint(100)));

vol.planes.push_back(Plane(bottomLeft.getOrigin(), bottomRight.getPoint(100), bottomLeft.getPoint(100)));

vol.planes.push_back(Plane(topRight.getOrigin(), topRight.getPoint(100), bottomRight.getPoint(100)));

PlaneBoundedVolumeList volList;

volList.push_back(vol);

mVolQuery->setVolumes(volList);

SceneQueryResult result = mVolQuery->execute();

deselectObjects();

SceneQueryResultMovableList::iterator itr;

for (itr = result.movables.begin(); itr != result.movables.end(); ++itr)

selectObject(*itr);

}

void deselectObjects()

{

std::list::iterator itr;

for (itr = mSelected.begin(); itr != mSelected.end(); ++itr)

(*itr)->getParentSceneNode()->showBoundingBox(false);

}

void selectObject(MovableObject *obj)

{

obj->getParentSceneNode()->showBoundingBox(true);

mSelected.push_back(obj);

}

private:

Vector2 mStart, mStop;

SceneManager *mSceneMgr;

PlaneBoundedVolumeListSceneQuery *mVolQuery;

std::list mSelected;

SelectionRectangle *mRect;

bool mSelecting;

static void swap(float &x, float &y)

{

float tmp = x;

x = y;

y = tmp;

}

};

class DemoApplication : public ExampleApplication

{

public:

DemoApplication()

: mRenderer(0), mSystem(0)

{

}

~DemoApplication()

{

if (mSystem)

delete mSystem;

if (mRenderer)

delete mRenderer;

}

protected:

CEGUI::OgreCEGUIRenderer *mRenderer;

CEGUI::System *mSystem;

void createScene(void)

{

mRenderer = new CEGUI::OgreCEGUIRenderer(mWindow,

Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mSceneMgr);

mSystem = new CEGUI::System(mRenderer);

CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLookSkin.scheme

");

CEGUI::MouseCursor::getSingleton().setImage((CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow");

mCamera->setPosition(-60, 100, -60);

mCamera->lookAt(60, 0, 60);

mSceneMgr->setAmbientLight(ColourValue::White);

for (int i = 0; i < 9; ++i)

for (int j = 0; j < 9; ++j)

{

Entity *ent = mSceneMgr->createEntity("Robot" + StringConverter::toString(i + j * 10), "robot.mesh");

SceneNode *node =

mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(i * 15, 0, j * 15));

node->attachObject(ent);

node->setScale(0.2, 0.2, 0.2);

}

}

void createFrameListener(void)

{

mFrameListener = new DemoListener(mWindow, mCamera, mSceneMgr);

mFrameListener->showDebugOverlay(true);

mRoot->addFrameListener(mFrameListener);

}

};

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32

#define WIN32_LEAN_AND_MEAN

#include "windows.h"

INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT) #else

int main(int argc, char **argv)

#endif

{

// Create application object

DemoApplication app;

try {

app.go();

} catch(Exception& e) {

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32

MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!",

MB_OK | MB_ICONERROR | MB_TASKMODAL);

#else

fprintf(stderr, "An exception has occurred: %s\n",

e.getFullDescription().c_str());

#endif

}

return 0;

}

6.利用3D Max软件制作模拟神州飞船返回地面的三维动画。

(略)

7.简述基于编程实现的动画与基于软件制作的动画的异同点。

编程实现方式:灵活,可以随心所欲进行动画创作,但要求较高,需要大量编程;

软件制作方式:方便,可以快速生成动画,但受限于所采用软件的功能强弱,仅需少量脚本;事实上,很难说哪一种方式更好,主要看需求,若软件制作方式能够完成的,且采购正版软件的费用在用户的承受范围之内,那不妨采用软件制作方式,而当软件制作方式不能实现所需要的功能和效果时,那就必须进行手工编程了。通常大些的动画作品往往采用两者结合的方式来开发。

8.编程实现卫星1、卫星2以及地球三个球体在空间中的运动旋转三维动画,环境不限。

/*三个球体在空间中的运动旋转三维动画*/

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define ESC 27

#define F 80 /*此数表示通常情况下操作者离电脑的距离(80厘米)*/

#define HIGHT 480 /*屏幕纵向分辩率*/

#define WIDE 640 /*屏幕横向分辨率*/

#define PAI 3.1415926 /*圆周率*/

#define TIME 0.2 /*转动间隔时间(每0.2秒转动5度)*/

typedef struct

{float x;

float y;

}_2D ; /*二维坐标点*/

typedef struct

{float x;

float y;

float z;

}_3D; /*三维坐标点*/

typedef struct

{int anglex;

int angley;

int anglez;

}Axle; /*轴向量(angle x,y,z分别表示向量与x,y,z轴的夹角)*/

typedef struct

{/*纬度圈由赤道加上南北半球的各四个纬度圈共9个纬度圈组成,经度等分成10个圈*/

/*所以用二维数组g[9][10]来记录经纬度交点*/

_3D *g[9][10];

/* temp[9][10]用来记录g[9][10]各点从三维变换到二维时的坐标*/

_2D *temp[9][10];

_3D *center; /*自转中心坐标,即球心坐标*/

_3D *round_center; /*公转中心坐标*/

float r; /*球体半径*/

}Globe; /*球体*/

float Observe_Mat[4][4],World_Mat[4][4]; /*观察坐标矩阵与世界坐标矩阵*/

float Sin[360],Cos[360]; /*存放三角函数值的两个数组,可以减少大量的浮点运算,以提高效率*/

size_t Size2D,Size3D,Sizeaxle,Sizeglobe;/*各结构体的尺寸*/

_3D *Observe; /*观察者所在的位置坐标*/

Globe *Moon1,*Moon2,*Earth; /*卫星1,卫星2,地球三个球体*/

int Zangle=5; /*转动角速度*/

/*建立三角函数表*/

void create_table()

{int i;

for(i=0;i<360;i++)

{Sin[i]=sin(i*PAI/180);

Cos[i]=cos(i*PAI/180);

}

}

/*初始化观察者位置*/

void init_observe()

{Observe=(_3D *)malloc(Size3D);

Observe->x=160;

Observe->y=0;

Observe->z=0;

}

/*把单位矩阵赋值给目标矩阵*/

void to_EMat(float mat[4][4])

{int i,j; for(i=0;i<4;i++)

for(j=0;j<4;j++)

mat[i][j]=0;

for(i=0;i<4;i++)

mat[i][i]=1;

}

/*把三维坐标点1的值赋给点2*/

void _3D_cpy(_3D *point1,_3D *point2)

{point1->x=point2->x;

point1->y=point2->y;

point1->z=point2->z;

}

/*把二维坐标点1的值赋给点2*/

void _2D_cpy(_2D *point1,_2D *point2)

{point1->x=point2->x;

point1->y=point2->y;

}

/*初始化各结构体的尺寸*/

void init_size()

{Size2D=sizeof(_2D);

Size3D=sizeof(_3D);

Sizeaxle=sizeof(Axle);

Sizeglobe=sizeof(Globe);

}

/*初始化观察坐标矩阵与世界坐标矩阵(设定为单位矩阵)*/

void init_Mat()

{int i,j;

for(i=0;i<4;i++)

for(j=0;j<4;j++)

{Observe_Mat[i][j]=0;

World_Mat[i][j]=0;

}

for(i=0;i<4;i++)

{Observe_Mat[i][i]=1;

World_Mat[i][i]=1;

}

}

/*矩阵1乘矩阵2得到矩阵3*/

void mat_mult(float mat1[4][4],float mat2[4][4],float mat3[4][4])

{int i,j;

for(i=0; i<4; i++)

for(j=0; j<4; j++)

mat3[i][j]=mat1[i][0]*mat2[0][j]+mat1[i][1]*mat2[1][j]+mat1[i][2]*mat2[2][j]+mat1[i][3]*mat2[ 3][j];

}

/*复制矩阵2到矩阵1*/

void mat_cpy(float mat1[4][4],float mat2[4][4]) {int i,j;

for(i=0;i<=3;i++)

for(j=0;j<=3;j++)

mat1[i][j]=mat2[i][j];

}

/*根据观察者位置建立观察坐标矩阵*/

void create_obMat()

{float _2Dr,_3Dr;

_2Dr=pow((pow(Observe->x,2)+pow(Observe->y,2)),0.5);

_3Dr=pow((pow(Observe->x,2)+pow(Observe->y,2)+pow(Observe->z,2)),0.5);

Observe_Mat[0][0]=Observe->y/_2Dr*-1;

Observe_Mat[0][1]=Observe->x*Observe->z/_2Dr/_3Dr*-1;

Observe_Mat[0][2]=Observe->x/_3Dr*-1;

Observe_Mat[1][0]=Observe->x/_2Dr;

Observe_Mat[1][1]=Observe->y*Observe->z/_2Dr/_3Dr*-1;

Observe_Mat[1][2]=Observe->y/_3Dr*-1;

Observe_Mat[2][1]=_2Dr/_3Dr;

Observe_Mat[2][2]=Observe->z/_3Dr*-1;

Observe_Mat[3][2]=_3Dr;

Observe_Mat[3][3]=1;

}

/*三维坐标点对指定矩阵变换以得到新的三维坐标*/

void _3D_mult_mat(_3D *Source,float mat[4][4]) {_3D *temp;

temp=(_3D *)malloc(Size3D);

temp->x=Source->x*mat[0][0]+Source->y*mat[1][0]+Source->z*mat[2][0]+mat[3][0];

temp->y=Source->x*mat[0][1]+Source->y*mat[1][1]+Source->z*mat[2][1]+mat[3][1];

temp->z=Source->x*mat[0][2]+Source->y*mat[1][2]+Source->z*mat[2][2]+mat[3][2];

_3D_cpy(Source,temp);

}

/*把三维坐标点从世界坐标变换成观察坐标*/

void world_to_ob(_3D *point1,_3D *point2)

{point2->x=point1->x*Observe_Mat[0][0]+point1->y*Observe_Mat[1][0]+

point1->z*Observe_Mat[2][0]+Observe_Mat[3][0];

point2->y=point1->x*Observe_Mat[0][1]+point1->y*Observe_Mat[1][1]+

point1->z*Observe_Mat[2][1]+Observe_Mat[3][1];

point2->z=point1->x*Observe_Mat[0][2]+point1->y*Observe_Mat[1][2]+

point1->z*Observe_Mat[2][2]+Observe_Mat[3][2];

}

/*把三维坐标投影为二维坐标*/

void _3Dto_2D(_3D *_3Dpoint,_2D *_2Dpoint)

{

_2Dpoint->x=WIDE/2+F*_3Dpoint->x/_3Dpoint->z;

_2Dpoint->y=HIGHT/2-F*_3Dpoint->y/_3Dpoint->z;

}

/*球体绕z轴转动后的坐标变换*/

void z_round(Globe *globe,int angle)

{float z[4][4]; int i,j; to_EMat(z);

z[0][0]=Cos[get_angle(angle)]; z[0][1]=Sin[get_angle(angle)];

z[1][0]=-z[0][1]; z[1][1]=z[0][0]; for(i=0;i<9;i++) for(j=0;j<10;j++) _3D_mult_mat(globe->g[i][j],z);

}

/*球体绕y轴转动后的坐标变换*/

void y_round(Globe *globe,int angle)

{float y[4][4]; int i,j; to_EMat(y);

y[0][0]=Cos[get_angle(angle)];

y[2][0]=Sin[get_angle(angle)];

y[0][2]=-y[2][0];

y[2][2]=y[0][0];

for(i=0;i<9;i++)

for(j=0;j<10;j++)

_3D_mult_mat(globe->g[i][j],y);

}

/*球体绕x轴转动后的坐标变换*/

void x_round(Globe *globe,int angle)

{float x[4][4];

int i,j;

to_EMat(x);

x[1][1]=Cos[get_angle(angle)];

x[1][2]=Sin[get_angle(angle)];

x[2][1]=-x[1][2];

x[2][2]=x[1][1];

for(i=0;i<9;i++)

for(j=0;j<10;j++)

_3D_mult_mat(globe->g[i][j],x);

}

/*初始化图形模式*/

void init_gph()

{int gd=DETECT,gm;

initgraph(&gd,&gm,"");

setfillstyle(SOLID_FILL,BLACK);

bar(0,0,640,480);

}

/*开辟一个用来存放球体数据的空间,并返回头地址*/ Globe *create_globe()

{Globe *p;

int i,j;

p=(Globe *)malloc(Sizeglobe);

for(i=0;i<9;i++)

for(j=0;j<10;j++)

{p->g[i][j]=(_3D *)malloc(Size3D);

p->temp[i][j]=(_2D *)malloc(Size2D);

}

p->center=(_3D *)malloc(Size3D);

p->round_center=(_3D *)malloc(Size3D);

return p;

}

/*把一个角化为0-360的角,要求是它的三角函数值不变*/ int get_angle(int angle)

{angle%=360;

if(angle<0)

angle=360+angle;

return angle;

}

/*给一个三维坐标赋值*/

_3D *get_3Dpoint(float x0,float y0,float z0)

{_3D *p;

p=(_3D *)malloc(Size3D);

p->x=x0;

p->y=y0;

p->z=z0;

return p;

}

/*给一个轴向量赋值*/

Axle *get_axle(int qx,int qy,int qz)

{Axle *p; p=(Axle *)malloc(Sizeaxle);

p->anglex=qx;

p->angley=qy;

p->anglez=qz;

return p;

}

/*从世界坐标原点平移球体到指定点(球体初始化时用)*/ void place_globe(Globe *globe)

{float tempf[4][4]; int i,j;

to_EMat(tempf);

tempf[3][0]=(globe->center)->x;

tempf[3][1]=(globe->center)->y;

tempf[3][2]=(globe->center)->z;

for(i=0;i<9;i++) for(j=0;j<10;j++)

_3D_mult_mat(globe->g[i][j],tempf);

}

/*球体初始化*/

void init_globe(Globe *globe,float r,_3D *thecenter,_3D *rnd_center) {int i,j;

globe->r=r;

for(i=-4;i<=4;i++)

for(j=0;j<=9;j++)

{(globe->g[i+4][j])->x=r*Cos[get_angle(i*18)]*Cos[get_angle(j*36)];

(globe->g[i+4][j])->y=r*Cos[get_angle(i*18)]*Sin[get_angle(j*36)];

(globe->g[i+4][j])->z=r*Sin[get_angle(i*18)]; }

_3D_cpy(globe->center,thecenter);

_3D_cpy(globe->round_center,rnd_center);

place_globe(globe);

}

/*把球体上的点从世界坐标变成观察坐标,然后再把观察坐标投影为二维坐标*/ void Wglobe_to_2D(Globe *globe)

{int i,j;

_3D *point;

for(i=0;i<9;i++)

for(j=0;j<10;j++)

{world_to_ob(globe->g[i][j],point);

_3Dto_2D(point,globe->temp[i][j]);

}

}

/*用指定颜色绘制球体*/

void draw_globe(Globe *g,int color)

{int i,j,n;

Wglobe_to_2D(g);

setcolor(color);

for(i=0;i<9;i++)

for(j=0;j<10;j++)

{n=j+1;

if(n==10)

n=0;

line((g->temp[i][j])->x,(g->temp[i][j])->y,(g->temp[i][n])->x,(g->temp[i][n])->y);

}

for(j=0;j<10;j++)

for(i=0;i<9;i++)

{n=i+1;

if(n==9)

n=0;

line((g->temp[i][j])->x,(g->temp[i][j])->y,(g->temp[n][j])->x,(g->temp[n][j])->y);

}

}

/*初始化*/

void init_start()

{int i;

_3D *p1,*p2,*p3,*p4;

init_gph();

setcolor(RED);

circle(320,240,200);

init_size();

create_table();

init_observe();

init_Mat();

create_obMat();

Moon1=create_globe();

Moon2=create_globe();

Earth=create_globe();

p1=get_3Dpoint(0,100,0);

p2=get_3Dpoint(0,-100,0);

p3=get_3Dpoint(0,0,0);

p4=get_3Dpoint(0,0,0);

init_globe(Moon1,20,p1,p4);

init_globe(Moon2,20,p2,p4);

init_globe(Earth,50,p3,p4);

draw_globe(Earth,BLUE);

draw_globe(Moon1,DARKGRAY);

draw_globe(Moon2,CYAN);

}

/*各球体随时间变化而在各自轨道上运行的动画(按任意键退出)*/ void roll()

{clock_t start,end;

int angle=0;

start=clock();

while(!kbhit())

{ end=clock();

if((end-start)/CLK_TCK>TIME)

{draw_globe(Moon1,BLACK);

draw_globe(Moon2,BLACK);

draw_globe(Earth,BLACK);

z_round(Moon1,Zangle);

x_round(Moon2,Zangle);

y_round(Earth,Zangle);

angle+=5;

if(get_angle(angle)<180)

{draw_globe(Moon1,DARKGRAY);

draw_globe(Earth,BLUE);

draw_globe(Moon2,CYAN); }

else {draw_globe(Moon2,CYAN);

draw_globe(Earth,BLUE);

draw_globe(Moon1,DARKGRAY);

}

start=clock();

}

}

}

/*主函数*/

void main()

{init_start();

roll();

getch();

closegraph();

}

9.利用3D Max软件制作一个通过运动捕获数据驱动的人体跳舞动画。

以下为人体跳舞动画的数据(BVH文件格式,帧数:641)

HIERARCHY

ROOT Hips

{

OFFSET 0.000000 0.000000 0.000000

CHANNELS 6 Xposition Yposition Zposition Zrotation Xrotation Yrotation JOINT LeftHip

{

OFFSET 7.620000 -9.238310 -2.558821

CHANNELS 3 Zrotation Xrotation Yrotation

JOINT LeftKnee

{

OFFSET 1.635636 -37.707061 -0.504193

CHANNELS 3 Zrotation Xrotation Yrotation

JOINT LeftAnkle

{

OFFSET -1.055091 -39.808909 -5.105526

CHANNELS 3 Zrotation Xrotation Yrotation

JOINT LeftAnkleEnd

{

OFFSET 0.161781 -3.108985 -3.102331

CHANNELS 3 Zrotation Xrotation Yrotation

End Site

{

OFFSET 2.878562 0.000000 14.803361

}

}

}

}

}

JOINT RightHip

{

OFFSET -7.620000 -9.238310 -2.558821

CHANNELS 3 Zrotation Xrotation Yrotation

JOINT RightKnee

{

OFFSET -1.635636 -37.707061 -0.504193

CHANNELS 3 Zrotation Xrotation Yrotation

JOINT RightAnkle

{

OFFSET 1.055091 -39.808909 -5.105526

CHANNELS 3 Zrotation Xrotation Yrotation

JOINT RightAnkleEnd

{

OFFSET -0.161781 -3.108985 -3.102331

CHANNELS 3 Zrotation Xrotation Yrotation

End Site

{

OFFSET -2.878562 0.000000 14.803361

}

}

}

}

}

JOINT Chest

{

OFFSET 0.000000 8.760765 -2.058116

CHANNELS 3 Zrotation Xrotation Yrotation

JOINT Chest1

{

OFFSET 0.000000 15.907688 -2.515476

CHANNELS 3 Zrotation Xrotation Yrotation

JOINT LeftCollar

{

OFFSET 7.620000 17.731891 -1.298057

CHANNELS 3 Zrotation Xrotation Yrotation

JOINT LeftShoulder

{

OFFSET 10.020731 -5.952668 -1.083241

CHANNELS 3 Zrotation Xrotation Yrotation

JOINT LeftElbow

{

OFFSET 1.885587 -25.859485 0.930100

CHANNELS 3 Zrotation Xrotation Yrotation

JOINT LeftWrist

{

OFFSET 0.846554 -25.454100 14.184019

CHANNELS 3 Zrotation Xrotation Yrotation

End Site

{

OFFSET 0.291292 -6.334709 2.092742

}

}

}

}

}

JOINT RightCollar

{

OFFSET -7.620000 17.731891 -1.298057

CHANNELS 3 Zrotation Xrotation Yrotation

JOINT RightShoulder

{

OFFSET -10.020731 -5.952668 -1.083241

CHANNELS 3 Zrotation Xrotation Yrotation

JOINT RightElbow

{

OFFSET -2.679268 -25.720547 0.930090

CHANNELS 3 Zrotation Xrotation Yrotation

JOINT RightWrist

{

OFFSET -2.694584 -25.525983 14.184019

CHANNELS 3 Zrotation Xrotation Yrotation

End Site

{

OFFSET -0.096341 -6.870344 2.092742

}

}

}

}

}

JOINT Neck

{

OFFSET 0.000000 20.958098 -1.099045

CHANNELS 3 Zrotation Xrotation Yrotation

JOINT Head

{

OFFSET 0.000000 10.216641 1.973092

CHANNELS 3 Zrotation Xrotation Yrotation

End Site

{

OFFSET 0.078579 5.419547 -3.206267

}

}

}

}

}

}

MOTION

Frames: 641

Frame Time: 0.016667

0.000000 92.668809 0.000000 -1.418150 -1.813778 1.551358 0.689888 3.327406

-0.859247 1.130747 -0.228818 1.254584 -1.623634 -1.280035 -1.630993

0. 0. 0. 1.824510 2.715929 -1.340315 -0.418511 1.329885 -2.816274

-1.030961 -1.372483 0.005722 0. 0. 0. 0.872136 -3.220527 0.115964 -0.333546 1.174799 -0.073181 -0.620219 0.253720 -0.712324 0.220018

1.082034 -1.046360 0.774511 1.865365

2.472620 -2.527258 2.251001 -2.541979

1.762009 0.233711 1.348375 -1.626996 0.837727 -

2.495193 1.909050 -0.716167

0.591083 1.975502 -0.950487 -1.243180 1.571879 -4.264962 -0.702246

-0.306606 -2.599164 -0.717736

0.000000 92.668809 0.000000 -1.418150 -1.813778 1.551358 0.689888 3.327406

-0.859247 1.130747 -0.228818 1.254584 -1.623634 -1.280035 -1.630993

0. 0. 0. 1.824510 2.715929 -1.340315 -0.418511 1.329885 -2.816274

-1.030961 -1.372483 0.005722 0. 0. 0. 0.875944 -3.214252 0.033520 -0.360659 1.294784 -0.010228 -0.598671 0.126772 -0.693526 0.220018

1.082034 -1.046360 0.774511 1.865365

2.472620 -2.527258 2.251001 -2.541979

1.783548 0.107654 1.372434 -1.626996 0.837727 -

2.495193 1.909050 -0.716167

0.591083 1.975502 -0.950487 -1.243180 1.595278 -4.391098 -0.678536

-0.306606 -2.599164 -0.717736

0.000000 92.668809 0.000000 -1.418150 -1.813778 1.551358 0.689888 3.327406

-0.859247 1.130747 -0.228818 1.254584 -1.623634 -1.280035 -1.630993

0. 0. 0. 1.824510 2.715929 -1.340315 -0.418511 1.329885 -2.816274

-1.030961 -1.372483 0.005722 0. 0. 0. 0.875944 -3.214252 0.033520 -0.360659 1.294784 -0.010228 -0.598671 0.126772 -0.693526 0.220018

1.082034 -1.046360 0.774511 1.865365

2.472620 -2.527258 2.251001 -2.541979

1.783548 0.107654 1.372434 -1.626996 0.837727 -

2.495193 1.909050 -0.716167

0.591083 1.975502 -0.950487 -1.243180 1.595278 -4.391098 -0.678536

-0.306606 -2.599164 -0.717736

-0.033994 92.650312 -0.067615 -1.359079 -1.632209 1.320629 0.641257

3.092517 -1.069062 1.061408 -0.189590 1.461075 -1.535235 -1.270134

-1.421167 0. 0. 0. 1.745378 2.528370 -1.374166 -0.385288 1.308892 -2.469833 -0.804326 -1.466872 -0.059152 0. 0. 0. 0.867755

-3.183760 -0.009656 -0.437359 1.305789 0.018470 -0.551228 0.079385

-0.616376 0.159417 1.203842 -0.904674 0.860118 1.875394 2.739311 -2.467621

2.299617 -2.574947 1.901581 -0.042760 1.528977 -1.676422 0.719820

-2.613490 2.063514 -0.739594 0.694514 1.954134 -0.979500 -1.280798

1.594252 -4.648172 -0.486710 -0.385097 -

2.553909 -0.582945

-0.046086 92.643539 -0.077613 -1.338509 -1.546978 1.139883 0.609156

3.009731 -0.886573 1.061408 -0.189590 1.461075 -1.535235 -1.270134

-1.421167 0. 0. 0. 1.715001 2.449114 -1.190200 -0.385288 1.308892 -2.469833 -0.804326 -1.466872 -0.059152 0. 0. 0. 0.889602

-3.090291 -0.007797 -0.458089 1.242818 0.023262 -0.536202 0.095866 -0.596430 0.098348 1.272080 -0.897184 0.896868 1.917253 2.871581 -2.478994

2.375323 -2.600479 1.909099 -0.071594 1.591013 -1.684950 0.605436

-2.663601 2.203442 -0.787676 0.687624 1.981345 -1.033943 -1.336747

1.560780 -4.755913 -0.470581 -0.387648 -

2.558382 -0.410210

-0.054578 92.640332 -0.124231 -1.338509 -1.546978 1.139883 0.626772

2.968767 -1.224301 1.021132 -0.157293 1.667244 -1.471569 -1.267844

-1.315200 0. 0. 0. 1.711246 2.363885 -1.271260 -0.369955 1.380857 -2.343870 -0.799311 -1.488050 -0.108243 0. 0. 0. 0.889602

-3.090291 -0.007797 -0.458089 1.242818 0.023262 -0.536202 0.095866 -0.596430 0.098348 1.272080 -0.897184 0.896868 1.917253 2.871581 -2.478994

2.375323 -2.600479 1.909099 -0.071594 1.591013 -1.684950 0.605436

-2.663601 2.203442 -0.787676 0.687624 1.981345 -1.033943 -1.336747

1.560780 -4.755913 -0.470581 -0.387648 -

2.558382 -0.410210

-0.087288 92.630759 -0.158766 -1.311612 -1.455428 0.956932 0.622511

2.856383 -1.175159 0.971549 -0.142332 1.710946 -1.435828 -1.264391

-1.236487 0. 0. 0. 1.671360 2.183096 -1.177965 -0.341086 1.435344 -2.247133 -0.826277 -1.476255 -0.117578 0. 0. 0. 0.901350

-3.023363 -0.008231 -0.489244 1.158710 0.078135 -0.504156 0.109120 -0.588511 0.012126 1.352620 -0.967604 0.954359 2.020205 2.884845 -2.447066

2.424042 -2.597248 1.917302 -0.038220 1.576298 -1.676386 0.460805

-2.714187 2.300985 -0.791744 0.768432 2.039752 -1.133961 -1.453232

1.532906 -4.823392 -0.528254 -0.394105 -

2.543707 -0.277608

-0.087288 92.630759 -0.158766 -1.311612 -1.455428 0.956932 0.622511

2.856383 -1.175159 0.971549 -0.142332 1.710946 -1.435828 -1.264391

-1.236487 0. 0. 0. 1.671360 2.183096 -1.177965 -0.341086 1.435344 -2.247133 -0.826277 -1.476255 -0.117578 0. 0. 0. 0.901350

-3.023363 -0.008231 -0.489244 1.158710 0.078135 -0.504156 0.109120 -0.588511 0.012126 1.352620 -0.967604 0.954359 2.020205 2.884845 -2.447066

2.424042 -2.597248 1.917302 -0.038220 1.576298 -1.676386 0.460805

-2.714187 2.300985 -0.791744 0.768432 2.039752 -1.133961 -1.453232

1.532906 -4.823392 -0.528254 -0.394105 -

2.543707 -0.277608

-0.133586 92.616448 -0.213278 -1.270445 -1.335811 0.745805 0.620777

2.697164 -1.228018 0.893675 -0.113041 1.826206 -1.371747 -1.259699

-1.110196 0. 0. 0. 1.618279 1.939573 -1.125245 -0.333024 1.547928 -2.082135 -0.831131 -1.517172 -0.132212 0. 0. 0. 0.907988

本文来源:https://www.bwwdw.com/article/1v2e.html

Top