OgreMadMard教程4翻译版Word格式文档下载.docx

上传人:b****6 文档编号:19901984 上传时间:2023-01-12 格式:DOCX 页数:16 大小:25.86KB
下载 相关 举报
OgreMadMard教程4翻译版Word格式文档下载.docx_第1页
第1页 / 共16页
OgreMadMard教程4翻译版Word格式文档下载.docx_第2页
第2页 / 共16页
OgreMadMard教程4翻译版Word格式文档下载.docx_第3页
第3页 / 共16页
OgreMadMard教程4翻译版Word格式文档下载.docx_第4页
第4页 / 共16页
OgreMadMard教程4翻译版Word格式文档下载.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

OgreMadMard教程4翻译版Word格式文档下载.docx

《OgreMadMard教程4翻译版Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《OgreMadMard教程4翻译版Word格式文档下载.docx(16页珍藏版)》请在冰豆网上搜索。

OgreMadMard教程4翻译版Word格式文档下载.docx

oTutorialDescription

oAfterviewportcreation

∙main.cpp

TutorialDescription

Inthisprogram,Icreatea 

ManualObject 

(likeintheprevioustutorial). 

在这个程序中,咱创建了一个手动创建对象(就像之前的教程一样)。

Thistimeitwillbealittlemorecomplicatedthanjustaquad. 

这此将会比一个正方形更加复杂一点。

Tobeabletomakeseveralcopiesofit,andatthesametimere-usethealreadycreated 

3Ddata,IwillconverttheOgre:

:

toanOgre:

Mesh. 

为了能多做几份拷贝,同时重用已经创建的数据,咱将用Ogre:

Mesh代替掉Ogre:

ManualObject。

Suchmeshcanbeusedtocreateseveral"

Entities"

这样的mesh可以用来创建多个实体。

An 

Entity 

isaninstanceofamesh,andallowdifferent 

material 

informationforeach 

entity. 

EntitiesareoftenthemostcommonobjectinaOgreapplication. 

一个实体是一个mesh的实例,并且允许不同的实体附加材质信息。

实体通常是ogre程序里最常见的单位。

DifferentEntitiescanhavedifferentmaterials,whilesharingthesamemesh. 

ItispossibletocreateEntitieswithdifferentmeshestoo. 

不同的实体可以拥有不同的材质,以其共享相同的mesh,还可以创建不同的mesh来创建实体。

Inordertomovean 

Entity,attachittoa 

SceneNode,andmovethis 

SceneNode.

为了移动实体,我们需要将实体绑定到节点上,然后移动节点。

Note:

Itwasreportedthatonsomevideodrivers(mesa/intel), 

ManualObject:

convertToMesh() 

produces 

somekindofdegenerated(invisible)mesh.Ifthatisthecaseforyou,pleaseupdateyourdrivers.

注意:

在一些显卡驱动中会回报这种(mesa/intel), 

somekindofdegenerated(invisible)mesh。

如果你遇见这种情况,请更新你的显卡驱动。

Afterviewportcreation

在视口创建后

¤

Ogre:

ManualObject*lManualObject=NULL;

{

ThemanualObjectcreationrequiresaname. 

ManualObject构造器需要一个名字:

Ogre:

StringlManualObjectName="

CubeWithAxes"

;

lManualObject=lScene->

createManualObject(lManualObjectName);

Alwaystellifyouwanttoupdatethe3D(vertex/index)laterornot. 

别忘记要告诉你的程序在稍后是否要更新3D(顶点/索引):

boollDoIWantToUpdateItLater=false;

lManualObject->

setDynamic(lDoIWantToUpdateItLater);

HereIcreateacubeinafirstpartwithtriangles,andthenaxes(inred/green/blue). 

这里咱要创建一个用三角形构成的立方体,andtheaxes(inred/green/blue)

【这句话咱猜是赋予其轴向颜色】

BaseWhiteNoLightingisthenameofa 

thatalreadyexistinsideOgre. 

BaseWhiteNoLighting是一个已经在ogre里面的材质的名字。

Ogre:

RenderOperation:

OT_TRIANGLE_LISTisakindofprimitive.

OT_TRIANGLE_LIST是一种原语。

floatlSize=0.7f;

begin("

BaseWhiteNoLighting"

Ogre:

OT_TRIANGLE_LIST);

{

floatcp=1.0f*lSize;

floatcm=-1.0f*lSize;

lManualObject->

position(cm,cp,cm);

//avertex

colour(Ogre:

ColourValue(0.0f,1.0f,0.0f,1.0f));

position(cp,cp,cm);

ColourValue(1.0f,1.0f,0.0f,1.0f));

position(cp,cm,cm);

ColourValue(1.0f,0.0f,0.0f,1.0f));

position(cm,cm,cm);

ColourValue(0.0f,0.0f,0.0f,1.0f));

position(cm,cp,cp);

ColourValue(0.0f,1.0f,1.0f,1.0f));

position(cp,cp,cp);

ColourValue(1.0f,1.0f,1.0f,1.0f));

position(cp,cm,cp);

ColourValue(1.0f,0.0f,1.0f,1.0f));

position(cm,cm,cp);

ColourValue(0.0f,0.0f,1.0f,1.0f));

facebehind/front

朝向背面/前面;

(其实这里指的是咱创建的立方体的正面和背面)

triangle(0,1,2);

triangle(2,3,0);

triangle(4,6,5);

triangle(6,4,7);

facetop/down

朝向上/下

triangle(0,4,5);

triangle(5,1,0);

triangle(2,6,7);

triangle(7,3,2);

faceleft/right

朝向左/右

triangle(0,7,4);

triangle(7,0,3);

triangle(1,5,6);

triangle(6,2,1);

}

end();

HereIhavefinishedmy 

construction. 

这里咱完成了咱的手动创建对象的构造。

Itispossibletoaddmorebegin()-end()thing,inordertouse 

differentrenderingoperationtypes,ordifferentmaterialsin1 

ManualObject.

很可能需要添加更多的begin()和end()来应对不同的渲染操作类型或是1个手动创建对象的不同材质。

Ogre:

OT_LINE_LIST);

floatlAxeSize=2.0f*lSize;

position(0.0f,0.0f,0.0f);

ColourValue:

Red);

position(lAxeSize,0.0f,0.0f);

Green);

position(0.0,lAxeSize,0.0);

Blue);

position(0.0,0.0,lAxeSize);

index(0);

index

(1);

index

(2);

index(3);

index(4);

index(5);

}

StringlNameOfTheMesh="

MeshCubeAndAxe"

StringlResourceGroup=Ogre:

ResourceGroupManager:

DEFAULT_RESOURCE_GROUP_NAME;

lManualObject->

convertToMesh(lNameOfTheMesh);

NowIcancreateseveralentitiesusingthatmesh

现在咱创建了几个使用mesh的实体。

intlNumberOfEntities=5;

for(intiter=0;

iter<

lNumberOfEntities;

++iter)

Entity*lEntity=lScene->

createEntity(lNameOfTheMesh);

NowIattachittoascenenode,sothatitbecomespresentinthescene.

现在咱将它绑定在节点上,

SceneNode*lNode=lRootSceneNode->

createChildSceneNode();

lNode->

attachObject(lEntity);

Imovethe 

SceneNode 

sothatitisvisibletothe 

camera.

咱移动了SceneNode,以便于摄像机的访问

floatlPositionOffset=float(1+iter*2)-(float(lNumberOfEntities));

translate(lPositionOffset,lPositionOffset,-10.0f);

}

(PS:

完成上面的代码,你应该可以看到几个彩色的正方体在屏幕中,还有几个彩色的坐标轴线)

main.cpp

//Inthisprogram,IcreateaManualObject(likeintheprevioustutorial).

//Thistimeitwillbealittlemorecomplicatedthanjustaquad.

//Tobeabletomakeseveralcopiesofit,andatthesametimere-usethealreadycreated

//3Ddata,IwillconverttheOgre:

ManualObjecttoanOgre:

Mesh.

//Suchmeshcanbeusedtocreateseveral"

.

//AnEntityisaninstanceofamesh,andallowdifferentmaterialinformationforeachentity.

//EntitiesareoftenthemostcommonobjectinaOgreapplication.

//DifferentEntitiescanhavedifferentmaterials,whilesharingthesamemesh.

//ItispossibletocreateEntitieswithdifferentmeshestoo.

//InordertomoveanEntity,attachittoaSceneNode,andmovethisSceneNode.

//

//Note:

Itwasreportedthatonsomevideodrivers(mesa/intel),convertToMeshproduces

//somekindofdegenerated(invisible)mesh.Ifthatisthecaseforyou,pleaseupdateyourdrivers.

//Iwillusestd:

auto_ptrsoIneedtoinclude'

memory'

//Ifyoudon'

tknowstd:

auto_ptr,youshouldchecksomeC++tutorials/lessononthismatter.

#include<

memory>

//Iwillcheckforstd:

exception.Ifyoudon'

tknowwhatexception/try/catchmeans,youshouldlearnC++first.

exception>

//ThesearesomefilesthatweneedtoincludetouseOgre3D.Notethatyoucanatthebeginningsusedirectly"

Ogre.h"

toincludelotsofcommonlyusedclasses.

#include"

OGRE/OgreRoot.h"

OGRE/OgreRenderSystem.h"

OGRE/OgreRenderWindow.h"

OGRE/OgreWindowEventUtilities.h"

OGRE/OgreManualObject.h"

OGRE/OgreEntity.h"

//HereIincludemyotherfiles,liketheoneforSimpleOgreInit...

SimpleOgreInit.h"

EasyDefines.h"

//IdeclareafunctioninwhichIwillmakemywholeapplication.

//Thisiseasythentoaddmorethingslaterinthatfunction.

//Themainwillcallthisfunctionandtakecareoftheglobaltry/catch.

voidAnOgreApplication()

{

//IconstructmyobjectthatwillallowmetoinitialiseOgreeasily.

OgreEasy:

SimpleOgreInitlOgreInit;

if(!

lOgreInit.initOgre())

{

std:

cout<

<

"

ImpossibletoinitOgrecorrectly."

std:

endl;

return;

//Iprefertobeabletoaccessmyvariablesdirectly.

Ogre:

Root*lRoot=lOgreInit.mRoot.get();

RenderWindow*lWindow=lOgreInit.mWindow;

//Icreateascenemanager.Thisislikea'

Scene'

inwhichIcanputlights,3dobjects,etc...

//Thescenemanagercontainsanarborescentgraphof'

SceneNodes'

.Tomanageelementsofthescene,

//IwillcreateSceneNodesintheSceneManager,andattachtheelementstothescenenodes.

//Firstparameter:

IselectakindofSceneManager.Thismayhaveahugeimpactonperfo

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 动态背景

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1