OgreMadMard教程4翻译版.docx

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

OgreMadMard教程4翻译版.docx

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

OgreMadMard教程4翻译版.docx

OgreMadMard教程4翻译版

MadMarxTutorial4        ManualObjecttoMesh

手动创建mesh

Foreword.

Ifyouprefertutorialsthatcomewithaframework=>checktheotherwikitutorialseries. 

Ifyouprefertutorialsthatgostepbystepwithoutaframework=>thispageshouldbeok.

加入你希望教程中是有framework的版本=>请在主页中寻找其他教程系列。

如果你希望教程中是没有framework,一步一步来实现代码的=>这一页就可以。

IassumeyouknowC++.Ifnot,thistutorialwillprobablybehardtounderstand!

咱假设你懂C++语言,否则你很难看得懂这页教程。

ThistutorialpresentsonlyafewelementsofOgre3D.

这个教程只适合有一定OGRE3D基础的开发者。

Youcandownloadthecodeandmediaforthistutorialatthebottomofthiswikipage. 

Thislittletutorialisanextractofabiggerprojectwhichcontainsmoretutorials&helperclasses. 

你可以下载本教程需要的媒体文件和代码在本页中,这是一个小小的教程,但是是从一个巨大的项目里面提取出来的,而那个巨大的项目里面则有更多的教程和帮助类。

Thisbiggerprojectisavaiblethere:

 

这个逼格(括弧笑)项目在这里:

Also,makesureyoureadthesetutorialsinorder!

同时,确认你能良好的完成本教程。

Tableofcontents

∙Foreword.

oTutorialDescription

oAfterviewportcreation

∙main.cpp

TutorialDescription

Inthisprogram,Icreatea ManualObject (likeintheprevioustutorial). 

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

Thistimeitwillbealittlemorecomplicatedthanjustaquad. 

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

Tobeabletomakeseveralcopiesofit,andatthesametimere-usethealreadycreated 

3Ddata,IwillconverttheOgre:

:

ManualObject 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), ManualObject:

:

convertToMesh() produces 

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 material thatalreadyexistinsideOgre. 

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

Ogre:

:

RenderOperation:

:

OT_TRIANGLE_LISTisakindofprimitive.

Ogre:

:

RenderOperation:

:

OT_TRIANGLE_LIST是一种原语。

¤floatlSize=0.7f;

lManualObject->begin("BaseWhiteNoLighting",Ogre:

:

RenderOperation:

:

OT_TRIANGLE_LIST);

{

floatcp=1.0f*lSize;

floatcm=-1.0f*lSize;

 

lManualObject->position(cm,cp,cm);//avertex

lManualObject->colour(Ogre:

:

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

lManualObject->position(cp,cp,cm);//avertex

lManualObject->colour(Ogre:

:

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

lManualObject->position(cp,cm,cm);//avertex

lManualObject->colour(Ogre:

:

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

lManualObject->position(cm,cm,cm);//avertex

lManualObject->colour(Ogre:

:

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

 

lManualObject->position(cm,cp,cp);//avertex

lManualObject->colour(Ogre:

:

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

lManualObject->position(cp,cp,cp);//avertex

lManualObject->colour(Ogre:

:

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

lManualObject->position(cp,cm,cp);//avertex

lManualObject->colour(Ogre:

:

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

lManualObject->position(cm,cm,cp);//avertex

lManualObject->colour(Ogre:

:

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

facebehind/front

朝向背面/前面;(其实这里指的是咱创建的立方体的正面和背面)

¤lManualObject->triangle(0,1,2);

lManualObject->triangle(2,3,0);

lManualObject->triangle(4,6,5);

lManualObject->triangle(6,4,7);

facetop/down

朝向上/下

¤lManualObject->triangle(0,4,5);

lManualObject->triangle(5,1,0);

lManualObject->triangle(2,6,7);

lManualObject->triangle(7,3,2);

faceleft/right

朝向左/右

¤lManualObject->triangle(0,7,4);

lManualObject->triangle(7,0,3);

lManualObject->triangle(1,5,6);

lManualObject->triangle(6,2,1);

}

lManualObject->end();

HereIhavefinishedmy ManualObject construction. 

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

Itispossibletoaddmorebegin()-end()thing,inordertouse 

differentrenderingoperationtypes,ordifferentmaterialsin1 ManualObject.

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

¤lManualObject->begin("BaseWhiteNoLighting",Ogre:

:

RenderOperation:

:

OT_LINE_LIST);

{

floatlAxeSize=2.0f*lSize;

lManualObject->position(0.0f,0.0f,0.0f);

lManualObject->colour(Ogre:

:

ColourValue:

:

Red);

lManualObject->position(lAxeSize,0.0f,0.0f);

lManualObject->colour(Ogre:

:

ColourValue:

:

Red);

lManualObject->position(0.0f,0.0f,0.0f);

lManualObject->colour(Ogre:

:

ColourValue:

:

Green);

lManualObject->position(0.0,lAxeSize,0.0);

lManualObject->colour(Ogre:

:

ColourValue:

:

Green);

lManualObject->position(0.0f,0.0f,0.0f);

lManualObject->colour(Ogre:

:

ColourValue:

:

Blue);

lManualObject->position(0.0,0.0,lAxeSize);

lManualObject->colour(Ogre:

:

ColourValue:

:

Blue);

 

lManualObject->index(0);

lManualObject->index

(1);

lManualObject->index

(2);

lManualObject->index(3);

lManualObject->index(4);

lManualObject->index(5);

}

lManualObject->end();

}

Ogre:

:

StringlNameOfTheMesh="MeshCubeAndAxe";

Ogre:

:

StringlResourceGroup=Ogre:

:

ResourceGroupManager:

:

DEFAULT_RESOURCE_GROUP_NAME;

lManualObject->convertToMesh(lNameOfTheMesh);

NowIcancreateseveralentitiesusingthatmesh

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

¤intlNumberOfEntities=5;

for(intiter=0;iter

{

Ogre:

:

Entity*lEntity=lScene->createEntity(lNameOfTheMesh);

NowIattachittoascenenode,sothatitbecomespresentinthescene.

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

¤Ogre:

:

SceneNode*lNode=lRootSceneNode->createChildSceneNode();

lNode->attachObject(lEntity);

Imovethe SceneNode sothatitisvisibletothe camera.

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

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

lNode->translate(lPositionOffset,lPositionOffset,-10.0f);

}

}

 (PS:

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

main.cpp

//Inthisprogram,IcreateaManualObject(likeintheprevioustutorial).

//Thistimeitwillbealittlemorecomplicatedthanjustaquad.

//Tobeabletomakeseveralcopiesofit,andatthesametimere-usethealreadycreated

//3Ddata,IwillconverttheOgre:

:

ManualObjecttoanOgre:

:

Mesh.

//Suchmeshcanbeusedtocreateseveral"Entities".

//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

//Iwillcheckforstd:

:

exception.Ifyoudon'tknowwhatexception/try/catchmeans,youshouldlearnC++first.

#include

 

//ThesearesomefilesthatweneedtoincludetouseOgre3D.Notethatyoucanatthebeginningsusedirectly"Ogre.h",toincludelotsofcommonlyusedclasses.

#include"OGRE/OgreRoot.h"

#include"OGRE/OgreRenderSystem.h"

#include"OGRE/OgreRenderWindow.h"

#include"OGRE/OgreWindowEventUtilities.h"

#include"OGRE/OgreManualObject.h"

#include"OGRE/OgreEntity.h"

 

//HereIincludemyotherfiles,liketheoneforSimpleOgreInit...

#include"SimpleOgreInit.h"

 

#include"EasyDefines.h"

 

//IdeclareafunctioninwhichIwillmakemywholeapplication.

//Thisiseasythentoaddmorethingslaterinthatfunction.

//Themainwillcallthisfunctionandtakecareoftheglobaltry/catch.

voidAnOgreApplication()

{

//IconstructmyobjectthatwillallowmetoinitialiseOgreeasily.

OgreEasy:

:

SimpleOgreInitlOgreInit;

 

if(!

lOgreInit.initOgre())

{

std:

:

cout<<"ImpossibletoinitOgrecorrectly."<

:

endl;

return;

}

 

//Iprefertobeabletoaccessmyvariablesdirectly.

Ogre:

:

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

Ogre:

:

RenderWindow*lWindow=lOgreInit.mWindow;

 

//Icreateascenemanager.Thisislikea'Scene',inwhichIcanputlights,3dobjects,etc...

//Thescenemanagercontainsanarborescentgraphof'SceneNodes'.Tomanageelementsofthescene,

//IwillcreateSceneNodesintheSceneManager,andattachtheelementstothescenenodes.

//Firstparameter:

IselectakindofSceneManager.Thismayhaveahugeimpactonperfo

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

当前位置:首页 > 经管营销 > 经济市场

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

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