本文整理汇总了C++中IrrlichtDevice类的典型用法代码示例。如果您正苦于以下问题:C++ IrrlichtDevice类的具体用法?C++ IrrlichtDevice怎么用?C++ IrrlichtDevice使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IrrlichtDevice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lineRender
/** Expect to see two diagonal lines overlaying a wall texture cube.
One line should run from green at the top left to red at the bottom right.
The other should run from cyan 100% transparent at the bottom left to
cyan 100% opaque at the top right. */
static bool lineRender(E_DRIVER_TYPE driverType)
{
IrrlichtDevice *device = createDevice( driverType, dimension2d<u32>(160, 120), 32);
if (!device)
return true; // Treat a failure to create a driver as benign; this saves a lot of #ifdefs
IVideoDriver* driver = device->getVideoDriver();
ISceneManager * smgr = device->getSceneManager();
stabilizeScreenBackground(driver);
logTestString("Testing driver %ls\n", driver->getName());
// Draw a cube background so that we can check that the pixels' alpha is working.
ISceneNode * cube = smgr->addCubeSceneNode(50.f, 0, -1, vector3df(0, 0, 60));
cube->setMaterialTexture(0, driver->getTexture("../media/wall.bmp"));
cube->setMaterialFlag(video::EMF_LIGHTING, false);
(void)smgr->addCameraSceneNode();
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
// Test for benign handling of offscreen pixel values as well as onscreen ones.
for(s32 x = -10; x < 170; ++x)
{
s32 y = 120 * x / 160;
driver->drawPixel((u32)x, (u32)y, SColor(255, 255 * x / 640, 255 * (640 - x) / 640, 0));
y = 120 - y;
driver->drawPixel((u32)x, (u32)y, SColor(255 * x / 640, 0, 255, 255));
}
driver->endScene();
bool result = takeScreenshotAndCompareAgainstReference(driver, "-drawPixel.png", 98.81f);
device->closeDevice();
device->run();
device->drop();
return result;
}
示例2: serializeAttributes
bool serializeAttributes()
{
bool result = true;
IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2d<u32>(1, 1));
assert(device);
if(!device)
{
logTestString("device creation failed in %s:%d\n", __FILE__, __LINE__ );
return false;
}
io::IFileSystem * fs = device->getFileSystem ();
if ( !fs )
{
return false;
}
result &= MemorySerialization(fs);
if ( !result )
{
logTestString("MemorySerialization failed in %s:%d\n", __FILE__, __LINE__ );
}
result &= XmlSerialization(fs, device->getVideoDriver());
if ( !result )
{
logTestString("XmlSerialization failed in %s:%d\n", __FILE__, __LINE__ );
}
device->closeDevice();
device->run();
device->drop();
return result;
}
示例3: main
int main() {
// ask user for driver
video::E_DRIVER_TYPE driverType = driverChoiceConsole();
if (driverType == video::EDT_COUNT)
return 1;
// create device with full flexibility over creation parameters
// you can add more parameters if desired, check irr::SIrrlichtCreationParameters
irr::SIrrlichtCreationParameters params;
params.DriverType = driverType;
params.WindowSize = core::dimension2d<u32>(1024, 768);
IrrlichtDevice* device = createDeviceEx(params);
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* env = device->getGUIEnvironment();
env->getSkin()->setFont(env->getFont("media/fontlucida.png"));
driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
// Add camera
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 100.0f, 0.05f);
camera->setPosition(core::vector3df(820, 100, 850));
camera->setTarget(core::vector3df(1530, 708, 1296));
camera->setFarValue(42000.0f);
// camera->setPosition(core::vector3df(50,50,-60));
// camera->setTarget(core::vector3df(-70,30,-60));
// disable mouse cursor
device->getCursorControl()->setVisible(false);
// Add terrain scene node
scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode("media/terrain-heightmap.bmp", 0, // parent node
-1, // node id
core::vector3df(0.f, 0.f, 0.f), // position
core::vector3df(0.f, 0.f, 0.f), // rotation
core::vector3df(7.f, 1.f, 7.f), // scale
video::SColor(255, 255, 255, 255), // vertexColor
5, // maxLOD
scene::ETPS_17, // patchSize
4 // smoothFactor
);
terrain->setMaterialFlag(video::EMF_LIGHTING, false);
terrain->setMaterialTexture(0, driver->getTexture("media/terrain-texture.jpg"));
terrain->setMaterialTexture(1, driver->getTexture("media/detailmap3.jpg"));
terrain->setMaterialType(video::EMT_DETAIL_MAP);
terrain->scaleTexture(1.0f, 100.0f);
// create triangle selector for the terrain
scene::ITriangleSelector* selector = smgr->createTerrainTriangleSelector(terrain, 0);
terrain->setTriangleSelector(selector);
// create collision response animator and attach it to the camera
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(selector, camera, core::vector3df(1, 1, 1), core::vector3df(0, 0, 0));
selector->drop();
camera->addAnimator(anim);
anim->drop();
// sphere
scene::IMeshSceneNode* sphere = smgr->addSphereSceneNode(25.f, 100);
sphere->setPosition(core::vector3df(800, 100, 800));
sphere->setScale(core::vector3df(2, 2, 2));
// Create decal manager
DecalManager* decalManager = new DecalManager(smgr);
decalManager->setTerrain(terrain);
decalManager->addMesh(sphere);
MyEventReceiver* receiver = new MyEventReceiver(decalManager, terrain, sphere);
device->setEventReceiver(receiver);
irr::video::SColor backgroundColor(10, 255, 255, 255);
irr::video::SColor textColor(255, 255, 255, 255);
int lastFPS = -1;
irr::core::vector3df position = irr::core::vector3df(800, 300, 800);
irr::core::vector3df dimension = irr::core::vector3df(1, 1, 1);
irr::core::vector3df normal = irr::core::vector3df(1, 1, 0);
irr::f32 textureRotation = 0;
irr::scene::ISceneNode* parent = 0;
irr::f32 lifeTime = 110;
irr::f32 distance = 110;
// decalManager->addDecal("media/decal.png", collisionPoint, irr::core::vector3df(size, size, size), normal, rotation, parent, lifetime, distance);
decalManager->addDecal("media/decal.png", position, dimension, normal, textureRotation, parent, lifeTime, distance);
while (device->run()) {
if (device->isWindowActive()) {
driver->beginScene(true, true, 0);
smgr->drawAll();
//.........这里部分代码省略.........
示例4: main
/*
OK, now for the more interesting part. First, create the Irrlicht device. As in
some examples before, we ask the user which driver he wants to use for this
example.
*/
int main()
{
// create device and exit if creation failed
IrrlichtDevice * device = createDevice(EDT_OPENGL,core::dimension2d<u32>(640, 480));
if (device == 0)
return 1; // could not create selected driver.
/* The creation was successful, now we set the event receiver and
store pointers to the driver and to the gui environment. */
device->setWindowCaption(L"Irrlicht Engine - User Interface Demo");
device->setResizable(true);
video::IVideoDriver* driver = device->getVideoDriver();
IGUIEnvironment* env = device->getGUIEnvironment();
const io::path mediaPath = getExampleMediaPath();
/*
To make the font a little bit nicer, we load an external font
and set it as the new default font in the skin.
To keep the standard font for tool tip text, we set it to
the built-in font.
*/
IGUISkin* skin = env->getSkin();
IGUIFont* font = env->getFont(mediaPath + "fonthaettenschweiler.bmp");
if (font)
skin->setFont(font);
skin->setFont(env->getBuiltInFont(), EGDF_TOOLTIP);
/*
We add three buttons. The first one closes the engine. The second
creates a window and the third opens a file open dialog. The third
parameter is the id of the button, with which we can easily identify
the button in the event receiver.
*/
env->addButton(rect<s32>(10,240,110,240 + 32), 0, GUI_ID_QUIT_BUTTON,
L"Quit", L"Exits Program");
env->addButton(rect<s32>(10,280,110,280 + 32), 0, GUI_ID_NEW_WINDOW_BUTTON,
L"New Window", L"Launches a new Window");
env->addButton(rect<s32>(10,320,110,320 + 32), 0, GUI_ID_FILE_OPEN_BUTTON,
L"File Open", L"Opens a file");
/*
Now, we add a static text and a scrollbar, which modifies the
transparency of all gui elements. We set the maximum value of
the scrollbar to 255, because that's the maximal value for
a color value.
Then we create an other static text and a list box.
*/
env->addStaticText(L"Transparent Control:", rect<s32>(150,20,350,40), true);
IGUIScrollBar* scrollbar = env->addScrollBar(true,
rect<s32>(150, 45, 350, 60), 0, GUI_ID_TRANSPARENCY_SCROLL_BAR);
scrollbar->setMax(255);
scrollbar->setPos(255);
setSkinTransparency( scrollbar->getPos(), env->getSkin());
// set scrollbar position to alpha value of an arbitrary element
scrollbar->setPos(env->getSkin()->getColor(EGDC_WINDOW).getAlpha());
env->addStaticText(L"Logging ListBox:", rect<s32>(10,110,350,130), true);
IGUIListBox * listbox = env->addListBox(rect<s32>(10, 140, 350, 210));
env->addEditBox(L"Editable Text", rect<s32>(350, 80, 550, 100));
// Store the appropriate data in a context structure.
SAppContext context;
context.device = device;
context.counter = 0;
context.listbox = listbox;
// Then create the event receiver, giving it that context structure.
MyEventReceiver receiver(context);
// And tell the device to use our custom event receiver.
device->setEventReceiver(&receiver);
/*
And at last, we create a nice Irrlicht Engine logo in the top left corner.
*/
env->addImage(driver->getTexture(mediaPath + "irrlichtlogo2.png"),
position2d<int>(10,10));
/*
That's all, we only have to draw everything.
*/
fluid_settings_t* settings;
//.........这里部分代码省略.........
示例5: QuakeShaderInitScene
void QuakeShaderInitScene()
{
if (!IrrlichtManager::GetIrrlichtManager()->GetDevice())
{
LogError("Error initializing Irrlicht");
return;
}
IrrlichtManager::GetIrrlichtManager()->GetDevice()->getTimer()->setTime(0);
scene::ISceneManager* smgr = IrrlichtManager::GetIrrlichtManager()->GetScene();
IrrlichtDevice* device = IrrlichtManager::GetIrrlichtManager()->GetDevice();
// Quake3 Shader controls Z-Writing
smgr->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);
//for Android
FileSystemZip* pFileSystem = (FileSystemZip*) FileManager::GetFileManager()->GetFileSystem(0);
//for Android
if (pFileSystem)
pFileSystem->SetRootDirectory("assets/game/quake");
//hack so the textures can be found. The quake map loader isn't all that smart
device->getFileSystem()->changeWorkingDirectoryTo((GetBaseAppPath() + "game/quake").c_str());
u32 i;
scene::IQ3LevelMesh* mesh;
scene::IMeshSceneNode* node;
scene::IMesh* geometry;
const scene::IMesh* additional_mesh;
mesh = (scene::IQ3LevelMesh*)smgr->getMesh("maps/20kdm2.bsp");
if (mesh)
{
geometry = mesh->getMesh(quake3::E_Q3_MESH_GEOMETRY);
node = smgr->addOctreeSceneNode(geometry, 0, -1, 4096);
}
if ( mesh )
{
// the additional mesh can be quite huge and is unoptimized
additional_mesh = mesh->getMesh(quake3::E_Q3_MESH_ITEMS);
#ifdef SHOW_SHADER_NAME
gui::IGUIFont *font = device->getGUIEnvironment()->getFont("media/fontlucida.png");
u32 count = 0;
#endif
for ( i = 0; i!= additional_mesh->getMeshBufferCount(); ++i )
{
const IMeshBuffer* meshBuffer = additional_mesh->getMeshBuffer(i);
const video::SMaterial& material = meshBuffer->getMaterial();
// The ShaderIndex is stored in the material parameter
const s32 shaderIndex = (s32) material.MaterialTypeParam2;
// the meshbuffer can be rendered without additional support, or it has no shader
const quake3::IShader* shader = mesh->getShader(shaderIndex);
if (0 == shader)
{
continue;
}
// we can dump the shader to the console in its
// original but already parsed layout in a pretty
// printers way.. commented out, because the console
// would be full...
// quake3::dumpShader ( Shader );
node = smgr->addQuake3SceneNode(meshBuffer, shader);
#ifdef SHOW_SHADER_NAME
count += 1;
core::stringw name( node->getName() );
node = smgr->addBillboardTextSceneNode(
font, name.c_str(), node,
core::dimension2d<f32>(80.0f, 8.0f),
core::vector3df(0, 10, 0));
#endif
}
}
quake3::IEntity search;
s32 index;
s32 notEndList;
u32 parsepos;
f32 angle;
core::vector3df pos;
const quake3::SVarGroup* group;
scene::ICameraSceneNode* camera;
camera = smgr->addCameraSceneNodeFPS();
if ( mesh )
{
quake3::tQ3EntityList& entityList = mesh->getEntityList();
search.name = "info_player_deathmatch";
index = entityList.binary_search(search);
//.........这里部分代码省略.........
示例6: main
int main()
{
// ask user for driver
video::E_DRIVER_TYPE driverType=driverChoiceConsole();
if (driverType==video::EDT_COUNT)
return 1;
// create device
IrrlichtDevice *device =
createDevice(driverType, core::dimension2d<u32>(640, 480), 16, false);
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
const io::path mediaPath = getExampleMediaPath();
device->getFileSystem()->addFileArchive(mediaPath + "map-20kdm2.pk3");
scene::IAnimatedMesh* q3levelmesh = smgr->getMesh("20kdm2.bsp");
scene::IMeshSceneNode* q3node = 0;
// The Quake mesh is pickable, but doesn't get highlighted.
if (q3levelmesh)
q3node = smgr->addOctreeSceneNode(q3levelmesh->getMesh(0), 0, IDFlag_IsPickable);
/*
So far so good, we've loaded the quake 3 level like in tutorial 2. Now,
here comes something different: We create a triangle selector. A
triangle selector is a class which can fetch the triangles from scene
nodes for doing different things with them, for example collision
detection. There are different triangle selectors, and all can be
created with the ISceneManager. In this example, we create an
OctreeTriangleSelector, which optimizes the triangle output a little
bit by reducing it like an octree. This is very useful for huge meshes
like quake 3 levels. After we created the triangle selector, we attach
it to the q3node. This is not necessary, but in this way, we do not
need to care for the selector, for example dropping it after we do not
need it anymore.
*/
scene::ITriangleSelector* selector = 0;
if (q3node)
{
q3node->setPosition(core::vector3df(-1350,-130,-1400));
selector = smgr->createOctreeTriangleSelector(
q3node->getMesh(), q3node, 128);
q3node->setTriangleSelector(selector);
// We're not done with this selector yet, so don't drop it.
}
/*
We add a first person shooter camera to the scene so that we can see and
move in the quake 3 level like in tutorial 2. But this, time, we add a
special animator to the camera: A Collision Response animator. This
animator modifies the scene node to which it is attached to in order to
prevent it moving through walls, and to add gravity to it. The
only thing we have to tell the animator is how the world looks like,
how big the scene node is, how much gravity to apply and so on. After the
collision response animator is attached to the camera, we do not have to do
anything more for collision detection, anything is done automatically.
The rest of the collision detection code below is for picking. And please
note another cool feature: The collision response animator can be
attached also to all other scene nodes, not only to cameras. And it can
be mixed with other scene node animators. In this way, collision
detection and response in the Irrlicht engine is really easy.
Now we'll take a closer look on the parameters of
createCollisionResponseAnimator(). The first parameter is the
TriangleSelector, which specifies how the world, against collision
detection is done looks like. The second parameter is the scene node,
which is the object, which is affected by collision detection, in our
case it is the camera. The third defines how big the object is, it is
the radius of an ellipsoid. Try it out and change the radius to smaller
values, the camera will be able to move closer to walls after this. The
next parameter is the direction and speed of gravity. We'll set it to
(0, -10, 0), which approximates to realistic gravity, assuming that our
units are metres. You could set it to (0,0,0) to disable gravity. And the
last value is just a translation: Without this, the ellipsoid with which
collision detection is done would be around the camera, and the camera would
be in the middle of the ellipsoid. But as human beings, we are used to have our
eyes on top of the body, with which we collide with our world, not in
the middle of it. So we place the scene node 50 units over the center
of the ellipsoid with this parameter. And that's it, collision
detection works now.
*/
// Set a jump speed of 3 units per second, which gives a fairly realistic jump
// when used with the gravity of (0, -10, 0) in the collision response animator.
scene::ICameraSceneNode* camera =
smgr->addCameraSceneNodeFPS(0, 100.0f, .3f, ID_IsNotPickable, 0, 0, true, 3.f);
camera->setPosition(core::vector3df(50,50,-60));
camera->setTarget(core::vector3df(-70,30,-60));
//.........这里部分代码省略.........
示例7: getLimitedDt
/** Returns the current dt, which guarantees a limited frame rate. If dt is
* too low (the frame rate too high), the process will sleep to reach the
* maxium frame rate.
*/
float MainLoop::getLimitedDt()
{
float dt = 0;
// If we are doing a replay, use the dt from the history file
if (World::getWorld() && history->replayHistory() )
{
dt = history->updateReplayAndGetDT();
return dt;
}
// In profile mode without graphics, run with a fixed dt of 1/60
if ((ProfileWorld::isProfileMode() && ProfileWorld::isNoGraphics()) ||
UserConfigParams::m_arena_ai_stats)
{
return 1.0f/60.0f;
}
IrrlichtDevice* device = irr_driver->getDevice();
m_prev_time = m_curr_time;
while( 1 )
{
m_curr_time = device->getTimer()->getRealTime();
dt = (float)(m_curr_time - m_prev_time);
const World* const world = World::getWorld();
if (UserConfigParams::m_fps_debug && world)
{
const LinearWorld *lw = dynamic_cast<const LinearWorld*>(world);
if (lw)
{
Log::verbose("fps", "time %f distance %f dt %f fps %f",
lw->getTime(),
lw->getDistanceDownTrackForKart(0),
dt*0.001f, 1000.0f / dt);
}
else
{
Log::verbose("fps", "time %f dt %f fps %f",
world->getTime(), dt*0.001f, 1000.0f / dt);
}
}
// Don't allow the game to run slower than a certain amount.
// when the computer can't keep it up, slow down the shown time instead
// But this can not be done in networking, otherwise the game time on
// client and server will not be in synch anymore
if(!NetworkConfig::get()->isNetworking())
{
static const float max_elapsed_time = 3.0f*1.0f / 60.0f*1000.0f; /* time 3 internal substeps take */
if (dt > max_elapsed_time) dt = max_elapsed_time;
}
// Throttle fps if more than maximum, which can reduce
// the noise the fan on a graphics card makes.
// When in menus, reduce FPS much, it's not necessary to push to the maximum for plain menus
const int max_fps = (StateManager::get()->throttleFPS() ? 30 : UserConfigParams::m_max_fps);
const int current_fps = (int)(1000.0f/dt);
if (m_throttle_fps && current_fps > max_fps && !ProfileWorld::isProfileMode())
{
int wait_time = 1000/max_fps - 1000/current_fps;
if(wait_time < 1) wait_time = 1;
PROFILER_PUSH_CPU_MARKER("Throttle framerate", 0, 0, 0);
StkTime::sleep(wait_time);
PROFILER_POP_CPU_MARKER();
}
else break;
}
dt *= 0.001f;
return dt;
} // getLimitedDt
示例8: main
/*
At first, we let the user select the driver type, then start up the engine, set
a caption, and get a pointer to the video driver.
*/
int main()
{
// create device
IrrlichtDevice *device = createDevice(video::EDT_OPENGL,
core::dimension2d<u32>(512, 384));
if (device == 0)
return 1; // could not create selected driver.
device->setWindowCaption(L"Irrlicht Engine - 2D Graphics Demo");
video::IVideoDriver* driver = device->getVideoDriver();
/*
All 2d graphics in this example are put together into one texture,
2ddemo.png. Because we want to draw colorkey based sprites, we need to
load this texture and tell the engine, which part of it should be
transparent based on a colorkey.
In this example, we don't tell it the color directly, we just say "Hey
Irrlicht Engine, you'll find the color I want at position (0,0) on the
texture.". Instead, it would be also possible to call
driver->makeColorKeyTexture(images, video::SColor(0,0,0,0)), to make
e.g. all black pixels transparent. Please note that
makeColorKeyTexture just creates an alpha channel based on the color.
*/
video::ITexture* images = driver->getTexture("../../lib/irr/media/2ddemo.png");
driver->makeColorKeyTexture(images, core::position2d<s32>(0,0));
/*
To be able to draw some text with two different fonts, we first load
them. Ok, we load just one. As the first font we just use the default
font which is built into the engine. Also, we define two rectangles
which specify the position of the images of the red imps (little flying
creatures) in the texture.
*/
gui::IGUIFont* font = device->getGUIEnvironment()->getBuiltInFont();
gui::IGUIFont* font2 =
device->getGUIEnvironment()->getFont("../../lib/irr/media/fonthaettenschweiler.bmp");
core::rect<s32> imp1(349,15,385,78);
core::rect<s32> imp2(387,15,423,78);
/*
Prepare a nicely filtering 2d render mode for special cases.
*/
driver->getMaterial2D().TextureLayer[0].BilinearFilter=true;
driver->getMaterial2D().AntiAliasing=video::EAAM_FULL_BASIC;
/*
Everything is prepared, now we can draw everything in the draw loop,
between the begin scene and end scene calls. In this example, we are
just doing 2d graphics, but it would be no problem to mix them with 3d
graphics. Just try it out, and draw some 3d vertices or set up a scene
with the scene manager and draw it.
*/
while(device->run() && driver)
{
if (device->isWindowActive())
{
u32 time = device->getTimer()->getTime();
driver->beginScene(true, true, video::SColor(255,120,102,136));
/*
First, we draw 3 sprites, using the alpha channel we
created with makeColorKeyTexture. The last parameter
specifies that the drawing method should use this alpha
channel. The last-but-one parameter specifies a
color, with which the sprite should be colored.
(255,255,255,255) is full white, so the sprite will
look like the original. The third sprite is drawn
with the red channel modulated based on the time.
*/
// draw fire & dragons background world
driver->draw2DImage(images, core::position2d<s32>(50,50),
core::rect<s32>(0,0,342,224), 0,
video::SColor(255,255,255,255), true);
// draw flying imp
driver->draw2DImage(images, core::position2d<s32>(164,125),
(time/500 % 2) ? imp1 : imp2, 0,
video::SColor(255,255,255,255), true);
// draw second flying imp with colorcylce
driver->draw2DImage(images, core::position2d<s32>(270,105),
(time/500 % 2) ? imp1 : imp2, 0,
video::SColor(255,(time) % 255,255,255), true);
/*
Drawing text is really simple. The code should be self
explanatory.
*/
//.........这里部分代码省略.........
示例9: main
int main()
{
Input input;
IrrlichtDevice *device = createDevice(video::EDT_DIRECT3D9, dimension2d<u32>(800, 600), 16, false, true, false, &input);
device->setWindowCaption(L"Seas of Gold");
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
E_DRIVER_TYPE driverType = driverChoiceConsole();
EffectHandler *effect = new EffectHandler(device, driver->getScreenSize(), false, true);
E_FILTER_TYPE filterType = (E_FILTER_TYPE)core::clamp<u32>((u32)3 - '1', 0, 4);
MapID currentMap;
int skyR = 30, skyG = 30, skyB = 70;
int timer = 0;
SColor sky = SColor(255, skyR, skyG, skyB);
float plPos_x = 0.0f, plPos_y = 0.0f, plPos_z = 0.0f;
bool updateCam = true;
bool menu1 = false;
int state = Main;
int frameCount = 0;
LoadMap loadMap;
Player player;
Interface playerInterface(driver);
ITriangleSelector* selector = 0;
ISceneNodeAnimator* anim = 0;
Vendor southVendor;
Vendor eastVendor;
Vendor northVendor;
//InitializeVendors(northVendor, southVendor, eastVendor, itemD);
//ItemDatabase* itemD = new ItemDatabase;
ItemDatabase itemD;
itemD.Initialize();
//initialize player's inventory
player.AddGold(1000);
player.getInventory()->addItem(itemD.getItem(bronzeOre), 50);
player.getInventory()->addItem(itemD.getItem(ironOre), 50);
player.getInventory()->addItem(itemD.getItem(goldOre), 50);
//initialize south vendor's inventory
southVendor.getInventory()->addItem(itemD.getItem(bronzeOre), 100);
southVendor.getInventory()->addItem(itemD.getItem(coalOre), 100);
southVendor.getInventory()->addItem(itemD.getItem(supplies), 1000);
//initialize north vendor's inventory
northVendor.getInventory()->addItem(itemD.getItem(obsidianOre), 50);
northVendor.getInventory()->addItem(itemD.getItem(supplies), 1000);
//initialize south vendor's inventory
eastVendor.getInventory()->addItem(itemD.getItem(goldOre), 100);
eastVendor.getInventory()->addItem(itemD.getItem(ironOre), 100);
eastVendor.getInventory()->addItem(itemD.getItem(supplies), 1000);
//Item item(0, "bronzeOre", "Sprites/ore_Bronze.png");
//Item item2 = item;
//Item* item2 = itemD.getItem(3);
//inventory.addItem(&item, 2);
//inventory.addItem(&item, 2);
//inventory.addItem(item2, 2);
//int test = 0;
// Load the map scene
//loadMap.Load(smgr, device, Map_Africa);
//loadMap.Load(smgr, device, Map_India);
//loadMap.Load(smgr, device, selector, plyrNode, anim, Map_England);
IAnimatedMeshSceneNode* plyrNode = player.loadPlayerNode(device, smgr);
//plyrNode->setDebugDataVisible((scene::E_DEBUG_SCENE_TYPE)(plyrNode->isDebugDataVisible() ^ scene::EDS_BBOX));
ICameraSceneNode* camera = smgr->addCameraSceneNode(0, plyrNode->getPosition() + vector3df(0, 2, 2), vector3df(0, 0, 100));
loadMap.Load(smgr, device, selector, plyrNode, anim, driver, Map_Africa);
currentMap = Map_Africa;
//loadMap.setCollisions(smgr, selector, plyrNode, anim);
if (loadMap.CollNode)
{
selector = smgr->createOctreeTriangleSelector(loadMap.CollNode->getMesh(), loadMap.CollNode, 32);
for (int i = 0; i < loadMap.CollNode->getMaterialCount(); i++)
{
loadMap.CollNode->getMaterial(i).NormalizeNormals = true;
}
loadMap.CollNode->setTriangleSelector(selector);
}
if (selector)
{
anim = smgr->createCollisionResponseAnimator(selector, plyrNode, vector3df(0.6f, 0.75f, 0.4f), core::vector3df(0.0f, -0.05f, 0.0f),
core::vector3df(0.0f, -0.725f, 0.0f));
plyrNode->addAnimator(anim);
}
ISceneCollisionManager* collMan = smgr->getSceneCollisionManager();
////////////// The Sun ////////////
ILightSceneNode *sun_node;
SLight sun_data;
//.........这里部分代码省略.........
示例10: testTransparentVertexAlphaMore
bool testTransparentVertexAlphaMore(E_DRIVER_TYPE driverType)
{
IrrlichtDevice *device = createDevice(driverType, dimension2d<u32>(160, 120));
if (!device)
return true;
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
if (driver->getColorFormat() != video::ECF_A8R8G8B8)
{
device->closeDevice();
device->run();
device->drop();
return true;
}
stabilizeScreenBackground(driver);
logTestString("Testing driver %ls\n", driver->getName());
IAnimatedMesh* mesh = smgr->getMesh("../media/sydney.md2");
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
IMeshSceneNode* cube = smgr->addCubeSceneNode(10.0f,0,-1,vector3df(-5,3,-15));
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setFrameLoop(0, 310);
node->setMaterialTexture( 0, driver->getTexture("../media/sydney.bmp") );
}
if (cube)
{
cube->getMaterial(0).MaterialType = EMT_TRANSPARENT_VERTEX_ALPHA;
cube->setMaterialTexture(0, driver->getTexture("../media/wall.bmp"));
cube->setMaterialFlag(EMF_LIGHTING, false);
smgr->getMeshManipulator()->setVertexColorAlpha(cube->getMesh(),128);
}
// second cube without texture
cube = smgr->addCubeSceneNode(10.0f,0,-1,vector3df(5,3,-15));
if (cube)
{
cube->getMaterial(0).MaterialType = EMT_TRANSPARENT_VERTEX_ALPHA;
cube->setMaterialFlag(EMF_LIGHTING, false);
smgr->getMeshManipulator()->setVertexColorAlpha(cube->getMesh(),128);
}
smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
driver->beginScene(true, true, SColor(0,200,200,200));
smgr->drawAll();
driver->endScene();
bool result = takeScreenshotAndCompareAgainstReference(driver, "-transparentVertexAlphaChannelMore.png", 99.18f);
device->closeDevice();
device->run();
device->drop();
return result;
}
示例11: main
/*
The start of the main function starts like in most other example. We ask the
user for the desired renderer and start it up. This time with the advanced
parameter handling.
*/
int main()
{
// ask user for driver
video::E_DRIVER_TYPE driverType=driverChoiceConsole();
if (driverType==video::EDT_COUNT)
return 1;
// create device with full flexibility over creation parameters
// you can add more parameters if desired, check irr::SIrrlichtCreationParameters
irr::SIrrlichtCreationParameters params;
params.DriverType=driverType;
params.WindowSize=core::dimension2d<u32>(640, 480);
IrrlichtDevice* device = createDeviceEx(params);
if (device == 0)
return 1; // could not create selected driver.
/*
First, we add standard stuff to the scene: A nice irrlicht engine
logo, a small help text, a user controlled camera, and we disable
the mouse cursor.
*/
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* env = device->getGUIEnvironment();
driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
// add irrlicht logo
env->addImage(driver->getTexture("../../media/irrlichtlogo2.png"),
core::position2d<s32>(10,10));
//set other font
env->getSkin()->setFont(env->getFont("../../media/fontlucida.png"));
// add some help text
env->addStaticText(
L"Press 'W' to change wireframe mode\nPress 'D' to toggle detail map\nPress 'S' to toggle skybox/skydome",
core::rect<s32>(10,421,250,475), true, true, 0, -1, true);
// add camera
scene::ICameraSceneNode* camera =
smgr->addCameraSceneNodeFPS(0,100.0f,1.2f);
camera->setPosition(core::vector3df(2700*2,255*2,2600*2));
camera->setTarget(core::vector3df(2397*2,343*2,2700*2));
camera->setFarValue(42000.0f);
// disable mouse cursor
device->getCursorControl()->setVisible(false);
/*
Here comes the terrain renderer scene node: We add it just like any
other scene node to the scene using
ISceneManager::addTerrainSceneNode(). The only parameter we use is a
file name to the heightmap we use. A heightmap is simply a gray scale
texture. The terrain renderer loads it and creates the 3D terrain from
it.
To make the terrain look more big, we change the scale factor of
it to (40, 4.4, 40). Because we don't have any dynamic lights in the
scene, we switch off the lighting, and we set the file
terrain-texture.jpg as texture for the terrain and detailmap3.jpg as
second texture, called detail map. At last, we set the scale values for
the texture: The first texture will be repeated only one time over the
whole terrain, and the second one (detail map) 20 times.
*/
// add terrain scene node
scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
"../../media/terrain-heightmap.bmp",
0, // parent node
-1, // node id
core::vector3df(0.f, 0.f, 0.f), // position
core::vector3df(0.f, 0.f, 0.f), // rotation
core::vector3df(40.f, 4.4f, 40.f), // scale
video::SColor ( 255, 255, 255, 255 ), // vertexColor
5, // maxLOD
scene::ETPS_17, // patchSize
4 // smoothFactor
);
terrain->setMaterialFlag(video::EMF_LIGHTING, false);
terrain->setMaterialTexture(0,
driver->getTexture("../../media/terrain-texture.jpg"));
terrain->setMaterialTexture(1,
driver->getTexture("../../media/detailmap3.jpg"));
terrain->setMaterialType(video::EMT_DETAIL_MAP);
terrain->scaleTexture(1.0f, 20.0f);
//.........这里部分代码省略.........
示例12: main
int main(int argc, char **argv) {
BSPdungeon dun(50,50,5);
IrrlichtDevice *device =createDevice( video::EDT_OPENGL, dimension2d<u32>(1280,720), 16,false, false, false, 0);
if (!device)
return 1;
device->setWindowCaption(L"Pangolin Kwest");
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
smgr->setAmbientLight(video::SColorf(0.1,0.1,0.1,1));
ILightSceneNode* mylight1 = smgr->addLightSceneNode( 0, core::vector3df(00,00,00), video::SColorf(0.3f,0.3f,0.3f), 30.0f, 1 );
//IGUIFont* myfont=guienv->getFont("./myfont.xml");
//if(myfont==0)exit(93);
//guienv->addMessageBox(L"Alertz!",L"You pangolin are been createrized. You totalleh ready to bash monstaz etc.!");
mylight1->enableCastShadow(true);
//guienv->addStaticText(L"Pangolin Kwest 3D",rect<s32>(10,10,260,22), true);
//-------------------------------------------
int x,y,z;
for(x=0;x<50;x++){
for(y=0;y<50;y++){
if(dun.map[x][y]==NIL){
for(z=0;z<3;z++){
ISceneNode* cueb=smgr->addCubeSceneNode(10);
cueb->setMaterialFlag(EMF_LIGHTING, true);
cueb->setMaterialTexture( 0, driver->getTexture("media/stdwall.jpg") );
// cueb->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0.25,0.5);
// cueb->getMaterial(0).getTextureMatrix(0).setTextureScale(0.0625,0.0625);
cueb->setPosition(vector3df(x*10,z*10,y*10));
}
}
// ISceneNode* cueb=smgr->addCubeSceneNode(10);
// cueb->setMaterialFlag(EMF_LIGHTING, true);
// cueb->setMaterialTexture( 0, driver->getTexture("media/stdfloor.jpg") );
// cueb->setPosition(vector3df(x*10,-10,y*10));
ISceneNode* cueb=smgr->addCubeSceneNode(10);
cueb->setMaterialFlag(EMF_LIGHTING, true);
cueb->setMaterialTexture( 0, driver->getTexture("media/stdup.jpg") );
cueb->setPosition(vector3df(x*10,30,y*10));
}
}
ISceneNode* cueb=smgr->addCubeSceneNode(500);
cueb->setMaterialFlag(EMF_LIGHTING, true);
cueb->setMaterialTexture( 0, driver->getTexture("media/stdfloor.jpg") );
cueb->setPosition(vector3df(250,-255,250));
//cueb->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0.25,0.5);
cueb->getMaterial(0).getTextureMatrix(0).setTextureScale(50,50);
//cueb->setScale(vector3df(0,-5,0));
//cueb->addshadowVolumeSceneNode();
//-------------------------------------------
int lastFPS;
//smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
ICameraSceneNode* mycam;
mycam=smgr->addCameraSceneNodeFPS(0,100.0f,0.025f);
mycam->setFOV(45);
mylight1->setParent(mycam);
while(device->run())
{
//mylight1->setPosition();
//mylight1->
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Pangolin Kwest 3D [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
//.........这里部分代码省略.........
示例13: main
/*
This is the main method. We can use void main() on every platform.
On Windows platforms, we could also use the WinMain method
if we would want to get rid of the console window, which pops up when
starting a program with main(), but to keep this example simple,
we use main().
*/
int main(int argc, char** argv)
{
/*
The most important function of the engine is the 'createDevice'
function. The Irrlicht Device can be created with it, which is the
root object for doing everything with the engine.
createDevice() has 7 paramters:
deviceType: Type of the device. This can currently be the Null-device,
the Software device, DirectX8, DirectX9, or OpenGL. In this example we use
EDT_SOFTWARE, but to try out, you might want to change it to
EDT_NULL, EDT_DIRECTX8 , EDT_DIRECTX9, or EDT_OPENGL.
windowSize: Size of the Window or FullscreenMode to be created. In this
example we use 640x480.
bits: Amount of bits per pixel when in fullscreen mode. This should
be 16 or 32. This parameter is ignored when running in windowed mode.
fullscreen: Specifies if we want the device to run in fullscreen mode
or not.
stencilbuffer: Specifies if we want to use the stencil buffer for drawing shadows.
vsync: Specifies if we want to have vsync enabled, this is only useful in fullscreen
mode.
eventReceiver: An object to receive events. We do not want to use this
parameter here, and set it to 0.
*/
IrrlichtDevice *device =
createDevice(EDT_SOFTWARE, dimension2d<s32>(640, 480), 16,
false, false, false, 0);
/*
Set the caption of the window to some nice text. Note that there is
a 'L' in front of the string. The Irrlicht Engine uses wide character
strings when displaying text.
*/
device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
/*
Get a pointer to the video driver, the SceneManager and the
graphical user interface environment, so that
we do not always have to write device->getVideoDriver(),
device->getSceneManager() and device->getGUIEnvironment().
*/
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
/*
We add a hello world label to the window, using the GUI environment.
*/
guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
rect<int>(10,10,200,22), true);
/*
To display something interesting, we load a Quake 2 model
and display it. We only have to get the Mesh from the Scene
Manager (getMesh()) and add a SceneNode to display the mesh.
(addAnimatedMeshSceneNode()). Instead of writing the filename
sydney.md2, it would also be possible to load a Maya object file
(.obj), a complete Quake3 map (.bsp) or a Milshape file (.ms3d).
By the way, that cool Quake 2 model called sydney was modelled
by Brian Collins.
*/
IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
/*
To let the mesh look a little bit nicer, we change its material a
little bit: We disable lighting because we do not have a dynamic light
in here, and the mesh would be totally black. Then we set the frame
loop, so that the animation is looped between the frames 0 and 310.
And at last, we apply a texture to the mesh. Without it the mesh
would be drawn using only a color.
*/
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setFrameLoop(0, 310);
node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
}
/*
To look at the mesh, we place a camera into 3d space at the position
(0, 30, -40). The camera looks from there to (0,5,0).
*/
smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
/*
Ok, now we have set up the scene, lets draw everything:
We run the device in a while() loop, until the device does not
want to run any more. This would be when the user closed the window
or pressed ALT+F4 in windows.
*/
while(device->run())
{
//.........这里部分代码省略.........
示例14: run
/** Run the actual main loop.
* The sequnce in which various parts of STK are updated is:
* - Determine next time step size (`getLimitedDt`). This takes maximum fps
* into account (i.e. sleep if the fps would be too high), and will actually
* slow down the in-game clock if the fps are too low (if more than 3/60 of
* a second have passed, more than 3 physics time steps would be needed,
* and physics do at most 3 time steps).
* - if a race is taking place (i.e. not only a menu being shown), call
* `updateRace()`, which is a thin wrapper around a call to
* `World::updateWorld()`:
* - Update history manager (which will either set the kart position and/or
* controls when replaying, or store the current info for a replay).
* This is mostly for debugging only (though available even in release
* mode).
* - Updates Replays - either storing data when not replaying, or
* updating kart positions/control when replaying).
* - Calls `WorldStatus::update()`, which updates the race state (e.g.
* go from 'ready' to 'set' etc), and clock.
* - Updates the physics (`Physics::update()`). This will simulate all
* physical objects for the specified time with bullet.
* - Updates all karts (`Kart::update()`). Obviously the update function
* does a lot more than what is described here, this is only supposed to
* be a _very_ high level overview:
* - Updates its rewinder (to store potentially changed controls
* as events) in `KartRewinder::update()`.
* - Calls `Moveable::update()`, which takes the new position from
* the physics and saves it (and computes dependent values, like
* heading, local velocity).
* - Updates its controller. This is either:
* - an AI using `SkiddingController::update()` (which then will
* compute the new controls), or
* - a player controller using `PlayerController::update()`, which will
* handle smooth steering (in case of digital input devices steering
* is adjusted a bit over time to avoid an instant change from all
* left to all right). Input events will be handled when updating
* the irrlicht driver later at the end of the main loop.
* - Updates kart animation (like rescue, ...) if one is shown atm.
* - Update attachments.
* - update physics, i.e. taking the current steering and updating
* the bullet raycast vehicle with that data. The settings are actually
* only used in the next frame when the physics are updated.
* - Updates all cameras via `Camera::update()`. The camera position and
* rotation is adjusted according to the position etc of the kart (and
* special circumstances like rescue, falling).
* - Updates all projectiles using the projectile manager. Some of the
* projectiles are mostly handled by the physics (e.g. a cake will mainly
* check if it's out of bounds), others (like basket ball) do all
* their aiming and movement here.
* - Updates the rewind manager to store rewind states.
* - Updates the music manager.
* - Updates the input manager (which only updates internal time, actual
* input handling follows late)
* - Updates the wiimote manager. This will read the data of all wiimotes
* and feed the corresponding events to the irrlicht event system.
* - Updates the STK internal gui engine. This updates all widgets, and
* e.g. takes care of the rotation of the karts in the KartSelection
* screen using the ModelViewWidget.
* - Updates STK's irrlicht driver `IrrDriver::update()`:
* - Calls Irrlicht's `beginScene()` .
* - Renders the scene (several times with different viewport if
* split screen is being used)
* - Calls `GUIEngine::render()`, which renders all widgets with the
* help of Irrlicht's GUIEnvironment (`drawAll()`). This will also
* handle all events, i.e. all input is now handled (e.g. steering,
* firing etc are all set in the corresponding karts depending on
* user input).
* - Calls Irrlicht's `endScene()`
*/
void MainLoop::run()
{
IrrlichtDevice* device = irr_driver->getDevice();
m_curr_time = device->getTimer()->getRealTime();
while(!m_abort)
{
PROFILER_PUSH_CPU_MARKER("Main loop", 0xFF, 0x00, 0xF7);
m_prev_time = m_curr_time;
float dt = getLimitedDt();
if (!m_abort && !ProfileWorld::isNoGraphics())
{
// Render the previous frame, and also handle all user input.
PROFILER_PUSH_CPU_MARKER("IrrDriver update", 0x00, 0x00, 0x7F);
irr_driver->update(dt);
PROFILER_POP_CPU_MARKER();
}
if (World::getWorld()) // race is active if world exists
{
PROFILER_PUSH_CPU_MARKER("Update race", 0, 255, 255);
updateRace(dt);
PROFILER_POP_CPU_MARKER();
} // if race is active
// We need to check again because update_race may have requested
// the main loop to abort; and it's not a good idea to continue
// since the GUI engine is no more to be called then.
// Also only do music, input, and graphics update if graphics are
// enabled.
//.........这里部分代码省略.........
示例15: main
/*
Ok, now the main-function:
First, we initialize the device, get the SourceManager and
VideoDriver, load an animated mesh from .md2 and a map from
.pk3. Because that's old stuff, I won't explain every step.
Just take care of the maps position.
*/
int main()
{
// ask user for driver
video::E_DRIVER_TYPE driverType=driverChoiceConsole();
if (driverType==video::EDT_COUNT)
return 1;
//Instance of the EventReceiver
MyEventReceiver receiver;
//Initialise the engine
IrrlichtDevice *device = createDevice(driverType,
dimension2du(ResX,ResY), 32, fullScreen,
false, false, &receiver);
if (!device)
return 1;
ISceneManager *smgr = device->getSceneManager();
IVideoDriver *driver = device->getVideoDriver();
//Load model
IAnimatedMesh *model = smgr->getMesh("../../media/sydney.md2");
if (!model)
return 1;
IAnimatedMeshSceneNode *model_node = smgr->addAnimatedMeshSceneNode(model);
//Load texture
if (model_node)
{
ITexture *texture = driver->getTexture("../../media/sydney.bmp");
model_node->setMaterialTexture(0,texture);
model_node->setMD2Animation(scene::EMAT_RUN);
//Disable lighting (we've got no light)
model_node->setMaterialFlag(EMF_LIGHTING,false);
}
//Load map
device->getFileSystem()->addFileArchive("../../media/map-20kdm2.pk3");
IAnimatedMesh *map = smgr->getMesh("20kdm2.bsp");
if (map)
{
ISceneNode *map_node = smgr->addOctreeSceneNode(map->getMesh(0));
//Set position
map_node->setPosition(vector3df(-850,-220,-850));
}
/*
Now we create our four cameras. One is looking at the model
from the front, one from the top and one from the side. In
addition there's a FPS-camera which can be controlled by the
user.
*/
// Create 3 fixed and one user-controlled cameras
//Front
camera[0] = smgr->addCameraSceneNode(0, vector3df(50,0,0), vector3df(0,0,0));
//Top
camera[1] = smgr->addCameraSceneNode(0, vector3df(0,50,0), vector3df(0,0,0));
//Left
camera[2] = smgr->addCameraSceneNode(0, vector3df(0,0,50), vector3df(0,0,0));
//User-controlled
camera[3] = smgr->addCameraSceneNodeFPS();
// don't start at sydney's position
if (camera[3])
camera[3]->setPosition(core::vector3df(-50,0,-50));
/*
Create a variable for counting the fps and hide the mouse:
*/
//Hide mouse
device->getCursorControl()->setVisible(false);
//We want to count the fps
int lastFPS = -1;
/*
There wasn't much new stuff - till now!
Only by defining four cameras, the game won't be splitscreen.
To do this you need several steps:
- Set the viewport to the whole screen
- Begin a new scene (Clear screen)
- The following 3 steps are repeated for every viewport in the splitscreen
- Set the viewport to the area you wish
- Activate the camera which should be "linked" with the viewport
- Render all objects
- If you have a GUI:
- Set the viewport the whole screen
- Display the GUI
- End scene
Sounds a little complicated, but you'll see it isn't:
*/
while(device->run())
//.........这里部分代码省略.........