`
java-mans
  • 浏览: 11451537 次
文章分类
社区版块
存档分类
最新评论

OGER SDK研究之一 Demo_BezierPath (贝塞尔曲线平滑补丁)

 
阅读更多

BezierPatch.h

/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/

Copyright (c) 2000-2006 Torus Knot Software Ltd
Also see acknowledgements in Readme.html

You may use this sample code for anything you like, it is not covered by the
LGPL like the rest of the engine.
-----------------------------------------------------------------------------
*/


/**
/file
Bezier.h 贝塞尔曲线平滑补丁

/brief
Specialisation of OGRE's framework application to show off
the bezier patch support.
将一些生硬的模型进行贝塞尔补丁使之平滑
*/

#include "ExampleApplication.h"

// Hack struct for test
PatchMeshPtr patch;
Pass* patchPass;

// Event handler to add ability to alter subdivision
// 事件监听类
class BezierListener : public ExampleFrameListener
{
protected:
public:
BezierListener(RenderWindow* win, Camera* cam)
: ExampleFrameListener(win, cam)
{

}

bool frameStarted(const FrameEvent& evt)
{
if( ExampleFrameListener::frameStarted(evt) == false )
return false;

static Real timeLapse = 0.0f;//timeLapse变量为一个记时器
static Real factor = 0.0; //factor 为patch中面数的调节比例参数(0~1)中
static bool wireframe = 0; //wireframe代表了渲染是采用线型还是实型


//timeSinceLastFrame为evt的成员变量,记录了上一帧到现在的时间
timeLapse += evt.timeSinceLastFrame;

// Prgressively grow the patch
// 调节 增长片
// 如果timeLapse大于1.0,则增加factor,并切换wireframe。切换渲染方式
if (timeLapse > 1.0f)
{
factor += 0.2;

if (factor > 1.0f)
{
wireframe = !wireframe;
//mCamera->setPolygonMode(wireframe ? PM_WIREFRAME : PM_SOLID);
patchPass->setPolygonMode(wireframe ? PM_WIREFRAME : PM_SOLID);
factor = 0.0f;

}

//设置Patch中模型面数
patch->setSubdivision(factor);
mDebugText = "Bezier subdivision factor: " + StringConverter::toString(factor);
timeLapse = 0.0f;
//计时器timeLapse归0
}

// Call default
return true;
}
};

//贝塞尔曲线应用程序
class BezierApplication : public ExampleApplication
{
protected:
VertexDeclaration* patchDecl;//顶点格式声明管理器
float* patchCtlPoints;//顶点缓冲指针

public:
BezierApplication() : patchDecl(NULL), patchCtlPoints(NULL) { }
~BezierApplication()
{
//释放顶点缓冲
if (patchCtlPoints)
delete [] patchCtlPoints;

// patch vertex declaration will be deleted automatically
}

protected:

#if OGRE_COMPILER == OGRE_COMPILER_MSVC
#pragma pack(push)
#pragma pack(1)
#endif
struct PatchVertex {
float x, y, z;
float nx, ny, nz;
float u, v;
};
#if OGRE_COMPILER == OGRE_COMPILER_MSVC
#pragma pack(pop)
#endif

// Just override the mandatory create scene method
//创建场景参数
void createScene(void)
{
// Set ambient light
//设置场景中的环境光
mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));

// Create a point light
//创建一个点光源
Light* l = mSceneMgr->createLight("MainLight");
// Accept default settings: point light, white diffuse, just set position
// NB I could attach the light to a SceneNode if I wanted it to move automatically with
// other objects, but I don't
// 设置点光源的类型为方向光
l->setType(Light::LT_DIRECTIONAL);
//设置点光源的方向
l->setDirection(-0.5, -0.5, 0);

// Create patch
// 创建 可调节的模型
// 取得顶点格式声明管理器
patchDecl = HardwareBufferManager::getSingleton().createVertexDeclaration();
//设置顶点格式
//由位置0起始的float3格式的位置 如float x,y,z;
patchDecl->addElement(0, 0, VET_FLOAT3, VES_POSITION);
//由float3起始的float3格式的法向量 如float nx,ny,nz;
patchDecl->addElement(0, sizeof(float)*3, VET_FLOAT3, VES_NORMAL);
//由float6起始的float2格式的纹理坐标 如 float u,v ;
patchDecl->addElement(0, sizeof(float)*6, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);

// Make a 3x3 patch for test
// 创建9个顶点大小的顶点数组
patchCtlPoints = (float*)( new PatchVertex[9] );

// Patch data
// 创建顶点结构指针指向顶点缓冲
PatchVertex *pVert = (PatchVertex*)patchCtlPoints;
// 填充顶点信息
pVert->x = -500.0; pVert->y = 200.0; pVert->z = -500.0;
pVert->nx = -0.5; pVert->ny = 0.5; pVert->nz = 0.0;
pVert->u = 0.0; pVert->v = 0.0;
pVert++;
pVert->x = 0.0; pVert->y = 500.0; pVert->z = -750.0;
pVert->nx = 0.0; pVert->ny = 0.5; pVert->nz = 0.0;
pVert->u = 0.5; pVert->v = 0.0;
pVert++;
pVert->x = 500.0; pVert->y = 1000.0; pVert->z = -500.0;
pVert->nx = 0.5; pVert->ny = 0.5; pVert->nz = 0.0;
pVert->u = 1.0; pVert->v = 0.0;
pVert++;

pVert->x = -500.0; pVert->y = 0.0; pVert->z = 0.0;
pVert->nx = -0.5; pVert->ny = 0.5; pVert->nz = 0.0;
pVert->u = 0.0; pVert->v = 0.5;
pVert++;
pVert->x = 0.0; pVert->y = 500.0; pVert->z = 0.0;
pVert->nx = 0.0; pVert->ny = 0.5; pVert->nz = 0.0;
pVert->u = 0.5; pVert->v = 0.5;
pVert++;
pVert->x = 500.0; pVert->y = -50.0; pVert->z = 0.0;
pVert->nx = 0.5; pVert->ny = 0.5; pVert->nz = 0.0;
pVert->u = 1.0; pVert->v = 0.5;
pVert++;

pVert->x = -500.0; pVert->y = 0.0; pVert->z = 500.0;
pVert->nx = -0.5; pVert->ny = 0.5; pVert->nz = 0.0;
pVert->u = 0.0; pVert->v = 1.0;
pVert++;
pVert->x = 0.0; pVert->y = 500.0; pVert->z = 500.0;
pVert->nx = 0.0; pVert->ny = 0.5; pVert->nz = 0.0;
pVert->u = 0.5; pVert->v = 1.0;
pVert++;
pVert->x = 500.0; pVert->y = 200.0; pVert->z = 800.0;
pVert->nx = 0.5; pVert->ny = 0.5; pVert->nz = 0.0;
pVert->u = 1.0; pVert->v = 1.0;
pVert++;

//由模型管理器中创建贝塞尔可调节模型API创建可调节模型
//参数1为创建的可调节模型的名称
//参数2为使用资源组类型为缺省类型
//参数3为顶点缓冲
//参数4为顶点格式声明
//参数5为宽
//参数6为高
//参数7,8为设定的最大的调节级别
//参数9为三角形两面都渲染
patch = MeshManager::getSingleton().createBezierPatch(
"Bezier1", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
patchCtlPoints, patchDecl,
3, 3, 5, 5, PatchSurface::VS_BOTH);

// Start patch at 0 detail
// 设置起始调节参数为0
patch->setSubdivision(0.0f);
// Create entity based on patch
//由可调节模型创建一个实体
Entity* patchEntity = mSceneMgr->createEntity("Entity1", "Bezier1");

//创建材质
MaterialPtr pMat = MaterialManager::getSingleton().create("TextMat",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

//材质中的效果设置纹理
pMat->getTechnique(0)->getPass(0)->createTextureUnitState( "BumpyMetal.jpg" );

//设置实体的材质
patchEntity->setMaterialName("TextMat");
patchPass = pMat->getTechnique(0)->getPass(0);

// Attach the entity to the root of the scene
// 将实体加入场景
mSceneMgr->getRootSceneNode()->attachObject(patchEntity);

//设置摄像机位置
mCamera->setPosition(500,500, 1500);
//设置摄像机观察点
mCamera->lookAt(0,200,-300);

}
void destroyScene(void)
{
// free up the pointer before we shut down OGRE
// 释放可调节模型
patch.setNull();
}
void createFrameListener(void)
{
// This is where we instantiate our own frame listener
//创建帧监听器
mFrameListener= new BezierListener(mWindow, mCamera);
//给根
mRoot->addFrameListener(mFrameListener);

}

};

Bezier.cpp:

/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/

Copyright (c) 2000-2006 Torus Knot Software Ltd
Also see acknowledgements in Readme.html

You may use this sample code for anything you like, it is not covered by the
LGPL like the rest of the engine.
-----------------------------------------------------------------------------
*/

/**
/file
Bezier.cpp
/brief
Shows OGRE's bezier patch feature
*/

#include "Bezier.h"

#ifdef __cplusplus
extern "C" {
#endif

#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
// 创建程序
BezierApplication app;

try {
app.go();
} catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL );
#else
std::cerr << "An exception has occured: " << e.getFullDescription();
#endif
}


return 0;
}
#ifdef __cplusplus
}
#endif

分享到:
评论

相关推荐

    Oger_3d_1.7_beginner's_guide中文第一章

    Oger3d1.7版本的初学者指南, 基本上就是step by step 模式,非常适合刚接触oger的童鞋

    超强OGRE中文教程bychenhong

    这是目前我能找到的最有实际意义的ogre教程,不泛泛而谈,而是面向实用,在这里向原书作者表示深深的感谢。

    易语言模块易语言OGRE类库1.1.rar

    易语言模块易语言OGRE类库1.1.rar 易语言模块易语言OGRE类库1.1.rar 易语言模块易语言OGRE类库1.1.rar 易语言模块易语言OGRE类库1.1.rar 易语言模块易语言OGRE类库1.1.rar 易语言模块易语言OGRE类库1.1.rar

    ogre最新技术

    ogre最新技术,最新开发文档资料,供初学者学习

    ogre 易语言指南

    ogre 指南编写改造的易语言指南,适合初学者使用。请阅读 有很多很有价值的内容 。讲得也很清楚。

    OGRE使用指南v0[1].01a.pdf

    本教程的目的是从使用者的角度将 OGRE 引擎最基本的概念和使用方法做一个较全面 的介绍。本教程隐藏了 OGRE 引擎内部的底层内容,力求做到简单、易懂,是 OGRE 引擎 的入门教程。

    OGRE-草地的制作

    OGRE-草地的制作 OGRE-草地的制作 OGRE-草地的制作 OGRE-草地的制作

    Ogre_VC9_AppWizard_1.7.1_2

    一堆人都在讲解怎么在VS下配置OGRE太难搞,花了好几天还不一定能用。然而这个工具只要一装就可以解决所有问题,简直就是一键配置。 配置方法: OGER库自己下载,必须是1.7.1版本 VS为VS2008版本 以上装好之后,然后...

    ORGE简体中文基础教程

    ORGE的基础教程,简体中文 非常适合入门的资料

    Ogre_3D_1.7_beginner_Guide中文版

    翻译的还是不错的,中英文对照,初学者可以借着了解下OGER编程

    toOgerBot:Telegram机器人,用于向Oger进行内联翻译

    安装此程序: :

    OGRE使用指南(入门教程)

    非常全面的OGER使用指南,如果你是新手,这是最好的一本入门教程!99%属于原创!

    跑步者

    跑步者该存储库包含一些附件脚本...nodes.tsv -o termlist.tsv在文档上运行OGER 您可以按以下步骤对文本文档运行OGER, python runner.py run-oger abstract.txt -t termlist.tsv -o out.json -f bioc_json注意:此命令

    HinautDominey2013_PLoS_ONE:有关论文《 Hinaut&Dominey》的源代码,《公共科学杂志》 2013年第1期-one source code

    Hinaut X,Dominey PF(2013)正面-纹波系统中语法结构的实时并行处理:使用储层计算的递归网络模拟研究。 公共科学学报8(2):e52946。 原代码仍然的的。 带有说明的自述文件是。 Python版本和依赖项 此代码...

    CEImagesetEditor-v0.6.2

    非常好用的一个截图编辑器,对于使用OGER开发的人或使用CEGUI的人来说很好用

    Ogre引擎-教程

    本教程由本人自己整理,内容来自网络各个角落。 内部包含7个文档和一个问题 里面有描述游戏大概架构的文档以及OGER引擎的文档

    使用ogre做的练练看游戏

    使用oger做的练练看游戏,里面用到了CEGUI做界面,FMOD播放声音,OIS控制输入,免费给大家分享,有任何问题请邮件: xieaiwanli@hotmail.com

    DevOO-Optimod

    DevOO-Optimod用法从命令行操作系统/Linux # start the app./gradlew run# run the tests./... 然后:文件 &gt; 导入 =&gt; Gradle 项目 执照麻省理工学院许可证 (MIT) 版权所有 (c) 2014 Robin Ricard、Edouard Oger、M

    eoger.me:个人网站

    这是目前托管在上的 Edouard Oger 个人网站的源代码存储库。 主要依赖 Node.js (0.10.x) 快递 (4.9.x) socket.io (1.2.x) React (0.12.x) Browserify (6.3.x) 吞咽(3.8.x) 安装 $ git clone ...

Global site tag (gtag.js) - Google Analytics