nxogretutorials / build / NxOgre101 / 101.cpp

本文 = 机器翻译+适当人工纠正

本教程教您使用通过创建所需的类NxOgre的最基础,创造一个盒子,通过小动物,与食人魔工作,然后关闭所有模拟。
开始! - 世界和场景
要启动的PhysX和NxOgre,你需要创建世界单身,那么一个场景,把事情英寸

要创建世界单身,只需调用静态createWorld在世界的功能,这将返回一个全新的世界对象 。你只需要在您的应用程序的生命周期做这一次。

/ /创建世界。
mWorld  =  NxOgre :世界:createWorld ();

最多可以有32个场景,运行一次,这些都是拥有世界创建 。大多数NxOgre对象的创建与描述类,它描述了在创建该对象的初始属性。在这种情况下,配置 SceneDescription类定义的属性,我们要创建我们的场景。这些属性我们明确地设置为重力(0,- 9.8f,0)和使用的硬件为 false ,所有其他属性保持其默认值。

/ /创建
 mScene  =  mWorld - > createScene (scene_description );

制作一份平面 - 平面和静态的几何结构
应放在第一件事,是地平面。飞机是无限的,在宽度和高度,和非空间相关的东西非常有用。飞机可以“附”,这是创建和场景所拥有的静态几何形状 ; mScene在这种情况下。

至于最NxOgre对象平面(归类为形状)的描述类; PlaneDescription。这是用来当创建一个刚体,在这种情况下,飞机只能连接到一个StaticGeometry。

 / /创建平面
 mScene - > createSceneGeometry (NxOgre :PlaneGeometryDescription ());

该代码是比它看起来要简单得多,场景:createSceneGeometry函数有三个参数;

形状描述 - 这没有默认值,必须给予。
位置/方向-这是一个默认值VEC3 0,0,0和第四纪 身份,并可以被排除在外。
RigidBodyDescription -这默认值,也可以被排除在外。
作为唯一的SceneGeometry独特的东西是飞机,那么只需要给予。

最后场景:createSceneGeometry不给的SceneGeometry对象,但作为我们不需要再次使用存储在任何地方,没有一点,但场景保持它的一个副本(因为NxOgre它创建的所有指针)和会自动删除它被破坏时的情景。

术语解释:

 

Actor演员

可移动物体的动态刚体;箱,门等。

Body机构

一个演员在屏幕上显示的通用术语。

Critter小动物

渲染系统为OGRE3D库。

Flour面粉

艺术家工具.flower 转换文件到无论是PhysX的.NXS或NxOgre .XM网格来回。

Flower花

基于文本的文件格式,描述了一个网格。

NxOgre

C + + PhysX的食人魔或任何其他的2D/3D渲染系统的包装。

RenderSystem渲染系统

适配器代码“画”在现实世界中发生的通过2D/3D库或框架屏幕上的是什么。

 

链接到NxOgre ,在成功的编译,构建解决方案,将所有相关的头文件和库复制到 SDK目录。这些都是你应该追加到您的项目链接器设置以下参数。

  • Additional Include Directories (.h) → c:/dev/NxOgre/sdk/
  • Additional Library Directories (.lib) → c:/dev/NxOgre/sdk/
  • Additional Dependencies → NxOgre.lib for Release or NxOgreDebug.lib for Debug.

Copy the file c:/dev/NxOgre/sdk/NxOgre.dll or NxOgreDebug.dll to your application directory.

 

PhysX的是什么呢?

您不需要链接到任何PhysX物理库或头,作为NxOgre不公开的PhysX API

的PhysX SDK版本编译NxOgre -是您需要提供的DLL,通常这些都是PhysX系统软件提供了PhysX的版本 。然而,根据版本,您可能需要复制适当的PhysXDLL到应用程序的目录(C:/ dev/PhysX/bin/win32 /) 。这些通常是;

  • PhysXCooking.dll
  • PhysXCore.dll
  • PhysXDevice.dll
  • PhysXLoader.dll
  • NxCharacter.dll(如果NxOgre编译NxOgreHasCharacterController设置为1),默认情况下,看到 NxOgreConfiguration.h

最简单的方法来检查,是没有的DLL运行编译的应用程序,。如果PhysX系统软件异常是由NxOgre提出,那么你可能会需要复制这些DLL。

最后编辑betajaen December 11, 2010

Txt 100644  211线(160 SLOC)   6.001 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
       
       
/**
NxOgre Tutorials - 101 - Box on a Plane
Copyright (c) 2009 Robin Southern, http://www.nxogre.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#include "OGRE/SdkSample.h"
#include "OGRE/SamplePlugin.h"
#include "NxOgre.h"
#include "critter.h"

using namespace Ogre ;
using namespace OgreBites ;

#define MaxStrength 1e7f

class _OgreSampleClassExport NxOgre101 : public SdkSample
{
 
public :
 
  NxOgre :: World * mWorld ;
  NxOgre :: Scene * mScene ;
  float mLastTimeStep ;
  NxOgre :: Material * mDefaultMaterial ;
  Critter :: RenderSystem * mRenderSystem ;
  Critter :: Body * mBody ;


  
  void setupPhysics ()
  {
  
   // Create the world.
   mWorld = NxOgre :: World :: createWorld ();
  
   mWorld -> getRemoteDebugger () -> connect ();

   // Create the scene
   NxOgre :: SceneDescription scene_description ;
   scene_description . mGravity = NxOgre :: Constants :: MEAN_EARTH_GRAVITY ;
   scene_description . mUseHardware = false ;

   mScene = mWorld -> createScene ( scene_description );
  
   // Set default material properties
   mDefaultMaterial = mScene -> getMaterial ( 0 );
   mDefaultMaterial -> setRestitution ( 0.1f );
   mDefaultMaterial -> setDynamicFriction ( 0.9 );
   mDefaultMaterial -> setStaticFriction ( 0.5 );
  
   // Plane creation
   mScene -> createSceneGeometry ( NxOgre :: PlaneGeometryDescription ());

   // Create the rendersystem.
   mRenderSystem = new Critter :: RenderSystem ( mScene , mSceneMgr );
  
   // mRenderSystem->setVisualisationMode(NxOgre::Enums::VisualDebugger_ShowAll);
   // Setup a BodyDescription.
   Critter :: BodyDescription bodyDescription ;
   bodyDescription . mMass = 40.0f ; // Set the mass to 40kg.
  
   // Finally create the body.
   mBody = mRenderSystem -> createBody ( NxOgre :: BoxDescription ( 1 , 1 , 1 ), NxOgre :: Vec3 ( 0 , 5 , 0 ), "cube.1m.mesh" , bodyDescription );
  
  }

  void stopPhysics ()
  {
   NxOgre :: World :: destroyWorld ();
  }
 
  bool keyPressed ( const OIS :: KeyEvent & evt )
  {
  
   NxOgre :: Vec3 force ;
  
   if ( evt . key == OIS :: KC_I )
    force . z += 1 ;
   else if ( evt . key == OIS :: KC_K )
    force . z -= 1 ;
   else if ( evt . key == OIS :: KC_J )
    force . x -= 1 ;
   else if ( evt . key == OIS :: KC_L )
    force . x += 1 ;
   else if ( evt . key == OIS :: KC_U )
    force . y += 1 ;
   else if ( evt . key == OIS :: KC_M )
    force . y -= 1 ;
  
   if ( ! force . isZero ())
    mBody -> addForce ( MaxStrength * force * mLastTimeStep );
  
   if ( evt . key == OIS :: KC_T )
    mBody -> setGlobalPosition ( NxOgre :: Vec3 ( 0 , 1 , 0 ));
  
   return SdkSample :: keyPressed ( evt );
  }

  void setupContent ()
  {
  
   ColourValue background = ColourValue ( 16.f / 255.f , 16.f / 255.f , 16.f / 255.f );
   mViewport -> setBackgroundColour ( background );
   mSceneMgr -> setFog ( Ogre :: FOG_EXP , background , 0.001 , 800 , 1000 );
  
   // set shadow properties
   mSceneMgr -> setShadowTechnique ( SHADOWTYPE_TEXTURE_MODULATIVE );
   mSceneMgr -> setShadowColour ( ColourValue ( 0.5 , 0.5 , 0.5 ));
   mSceneMgr -> setShadowTextureSize ( 1024 );
   mSceneMgr -> setShadowTextureCount ( 1 );

   // create a floor mesh resource
   MeshManager :: getSingleton (). createPlane ( "floor" , ResourceGroupManager :: DEFAULT_RESOURCE_GROUP_NAME ,
   Plane ( Vector3 :: UNIT_Y , 0 ), 1000 , 1000 , 1 , 1 , true , 1 , 1 , 1 , Vector3 :: UNIT_Z );

   // create a floor entity, give it a material, and place it at the origin
   Entity * floor = mSceneMgr -> createEntity ( "Floor" , "floor" );
   floor -> setMaterialName ( "ground-from-nxogre.org" );
   floor -> setCastShadows ( false );
   mSceneMgr -> getRootSceneNode () -> attachObject ( floor );

   // use a small amount of ambient lighting
   mSceneMgr -> setAmbientLight ( ColourValue ( 0.3 , 0.3 , 0.3 ));

   // add a bright light above the scene
   Light * light = mSceneMgr -> createLight ();
   light -> setType ( Light :: LT_POINT );
   light -> setPosition ( - 10 , 40 , 20 );
   light -> setSpecularColour ( ColourValue :: White );
  
   mCamera -> setPosition ( 10 , 10 , 10 );
   mCamera -> lookAt ( 0 , 0 , 0 );
   mCamera -> setNearClipDistance ( 0.02f );
   mCamera -> setFarClipDistance ( 1000.0f );
   mCameraMan -> setTopSpeed ( 7.5 );
   setupPhysics ();
  }
 
  void cleanupContent ()
  {
   stopPhysics ();
  }
 
  bool frameRenderingQueued ( const FrameEvent & evt )
  {
   // Advance NxOgre.
   mWorld -> advance ( evt . timeSinceLastFrame );
  
   mLastTimeStep = mScene -> getTimeStep (). getModified ();

   // Don't let the camera go underground.
   if ( mCamera -> getPosition (). y < 0.5f )
   {
    Ogre :: Vector3 pos = mCamera -> getPosition ();
    pos . y = 0.5f ;
    mCamera -> setPosition ( pos );
   }

   return SdkSample :: frameRenderingQueued ( evt );
  }

  NxOgre101 ()
  {
   mInfo [ "Title" ] = "NxOgre 101" ;
   mInfo [ "Description" ] = "NxOgre 101 - Box on a Plane" ;
   mInfo [ "Thumbnail" ] = "thumb_skybox.png" ;
   mInfo [ "Category" ] = "Physics" ;
   mInfo [ "Help" ] = "This is a box on a plane." ;
  }

};

SamplePlugin * sp ;
Sample * s ;

extern "C" _OgreSampleExport void dllStartPlugin ()
{
s = new NxOgre101 ;
sp = OGRE_NEW OgreBites :: SamplePlugin ( s -> getInfo ()[ "Title" ] + " Sample" );
sp -> addSample ( s );
Ogre :: Root :: getSingleton (). installPlugin ( sp );
}

extern "C" _OgreSampleExport void dllStopPlugin ()
{
Ogre :: Root :: getSingleton (). uninstallPlugin ( sp );
OGRE_DELETE sp ;
delete s ;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值