本文整理汇总了C++中MyEventReceiver::IsKeyDown方法的典型用法代码示例。如果您正苦于以下问题:C++ MyEventReceiver::IsKeyDown方法的具体用法?C++ MyEventReceiver::IsKeyDown怎么用?C++ MyEventReceiver::IsKeyDown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyEventReceiver
的用法示例。
在下文中一共展示了MyEventReceiver::IsKeyDown方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main_loop
void main_loop()
{
device->run();
// Work out a frame delta time.
const u32 now = device->getTimer()->getTime();
const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
then = now;
/* Check if keys W, S, A or D are being held down, and move the
sphere node around respectively. */
core::vector3df nodePosition = node->getPosition();
if(receiver.IsKeyDown(irr::KEY_KEY_W))
nodePosition.Y += MOVEMENT_SPEED * frameDeltaTime;
else if(receiver.IsKeyDown(irr::KEY_KEY_S))
nodePosition.Y -= MOVEMENT_SPEED * frameDeltaTime;
if(receiver.IsKeyDown(irr::KEY_KEY_A))
nodePosition.X -= MOVEMENT_SPEED * frameDeltaTime;
else if(receiver.IsKeyDown(irr::KEY_KEY_D))
nodePosition.X += MOVEMENT_SPEED * frameDeltaTime;
node->setPosition(nodePosition);
driver->beginScene(true, true, video::SColor(255,113,113,133));
smgr->drawAll(); // draw the 3d scene
device->getGUIEnvironment()->drawAll(); // draw the gui environment (the logo)
driver->endScene();
}
示例2: main
int main()
{
MyEventReceiver receiver;
IrrlichtDevice* device = createDevice(video::EDT_OPENGL,
core::dimension2d<u32>(640, 480), 16, false, false, false, &receiver);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
smgr->addLightSceneNode(0,vector3df(50,50,50));
ICameraSceneNode *camera = smgr->addCameraSceneNode();
IMeshSceneNode *node = smgr->addCubeSceneNode();
node->setPosition(vector3df(0,75,0));
camera->setTarget(vector3df(0,1,0));
smgr->getMeshManipulator()->setVertexColors(node->getMesh(), SColor(0,0,255,255));
smgr->addLightSceneNode();
while(device->run()){
if(receiver.IsKeyDown(irr::KEY_LEFT)){
node->setPosition(node->getPosition()+vector3df(0,0,-0.1));
}
else if(receiver.IsKeyDown(irr::KEY_RIGHT)){
node->setPosition(node->getPosition()+vector3df(0,0,0.1));
}
else if(receiver.IsKeyDown(irr::KEY_SPACE)){
}
driver->beginScene(true, true, SColor(123,100,100,100));
smgr->drawAll();
driver->endScene();
}
return 0;
}
示例3: main
//.........这里部分代码省略.........
bool rkf = false;
//Game loop
while (device->run())
{
//Create a list of all entities
EntityList.clear();
vector<Entity*> EnemyList( EnemyManager.GetEntityList() );
EntityList.insert( EntityList.end(), EnemyList.begin(), EnemyList.end() );
/* * * * * * * * * * * * * * */
/* Player switching module */
/* * * * * * * * * * * * * * */
for (int i = 0; i < PlayerManager.Size; i++)
PlayerManager.GetEntity(i)->CheckIfDead();
PlayerManager.ManageCharacterSwitching(Receiver);
/* * * * * * * * * * * */
/* Pathfinding module */
/* * * * * * * * * * * */
PlayerManager.GetCurrentEntity()->UpdatePathDisplayTimer();
if (Receiver.MouseState.LeftButtonDown && PlayerManager.GetCurrentEntity()->NewPathDisplayTimer < 1)
PlayerManager.GetCurrentEntity()->CreatePathToDestination(EntityList,smgr,Receiver,Cursor->getPosition(),dimension2d<s32>(MR.XSize,MR.YSize),MG.Convert());
/* * * * * * * * * * * * * */
/* Update position module */
/* * * * * * * * * * * * * */
PlayerManager.GetCurrentEntity()->Position();
/* * * * * * * * * * * */
/* Follow path module */
/* * * * * * * * * * * */
if (Receiver.IsKeyDown(Receiver.KeyConfig.FOLLOW_PATH))
PlayerManager.GetCurrentEntity()->FollowPath(EntityList);
/* * * * * * * * * */
/* End turn module */
/* * * * * * * * * */
if (Receiver.IsKeyDown(Receiver.KeyConfig.END_TURN) && !rkf)
{
rkf = true;
PlayerManager.EndTurn();
EnemyManager.AI_StartTurn(EntityList, PlayerManager, smgr, Receiver, irr::core::dimension2d<s32>(MR.XSize,MR.YSize), MG.Convert(), MR.MetaTriangleSelector, MR.MetaCoverTriangleSelector);
PlayerManager.StartTurn();
}
else if (!Receiver.IsKeyDown(Receiver.KeyConfig.END_TURN))
rkf = false;
/* * * * * * * * */
/* Cursor module */
/* * * * * * * * */
Cursor->setPosition( vftovi(MouseTo3D( Receiver, MR.CollisionManager, MR.TriSelector)) );
/* * * * * * * * */
/* Camera module */
/* * * * * * * * */
gameCam.Update(Receiver,PlayerManager.GetCurrentEntity()->Node);
/* * * * * * * * * * * * */
/* Stats monitor module */
/* * * * * * * * * * * * */
for (int i=0;i<PlayerManager.Size;i++)
PlayerManager.GetEntity(i)->Stats.MonitorAll();
示例4: main
//.........这里部分代码省略.........
but this only works with MD2 animations, and so you know how to
start other animations. But a good advice is to not use
hardcoded frame-numbers...
*/
anms->setMaterialFlag(video::EMF_LIGHTING, false);
anms->setFrameLoop(0, 13);
anms->setAnimationSpeed(15);
// anms->setMD2Animation(scene::EMAT_RUN);
anms->setScale(core::vector3df(2.f,2.f,2.f));
anms->setRotation(core::vector3df(0,-90,0));
// anms->setMaterialTexture(0, driver->getTexture(mediaPath + "sydney.bmp"));
}
/*
To be able to look at and move around in this scene, we create a first
person shooter style camera and make the mouse cursor invisible.
*/
smgr->addCameraSceneNodeFPS();
device->getCursorControl()->setVisible(false);
/*
Add a colorful irrlicht logo
*/
device->getGUIEnvironment()->addImage(
driver->getTexture(mediaPath + "irrlichtlogoalpha2.tga"),
core::position2d<s32>(10,20));
gui::IGUIStaticText* diagnostics = device->getGUIEnvironment()->addStaticText(
L"", core::rect<s32>(10, 10, 400, 20));
diagnostics->setOverrideColor(video::SColor(255, 255, 255, 0));
/*
We have done everything, so lets draw it. We also write the current
frames per second and the name of the driver to the caption of the
window.
*/
int lastFPS = -1;
// In order to do framerate independent movement, we have to know
// how long it was since the last frame
u32 then = device->getTimer()->getTime();
// This is the movemen speed in units per second.
const f32 MOVEMENT_SPEED = 5.f;
while(device->run())
{
// Work out a frame delta time.
const u32 now = device->getTimer()->getTime();
const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
then = now;
/* Check if keys W, S, A or D are being held down, and move the
sphere node around respectively. */
core::vector3df nodePosition = node->getPosition();
if(receiver.IsKeyDown(irr::KEY_KEY_W))
nodePosition.Y += MOVEMENT_SPEED * frameDeltaTime;
else if(receiver.IsKeyDown(irr::KEY_KEY_S))
nodePosition.Y -= MOVEMENT_SPEED * frameDeltaTime;
if(receiver.IsKeyDown(irr::KEY_KEY_A))
nodePosition.X -= MOVEMENT_SPEED * frameDeltaTime;
else if(receiver.IsKeyDown(irr::KEY_KEY_D))
nodePosition.X += MOVEMENT_SPEED * frameDeltaTime;
node->setPosition(nodePosition);
driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,113,113,133));
smgr->drawAll(); // draw the 3d scene
device->getGUIEnvironment()->drawAll(); // draw the gui environment (the logo)
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw tmp(L"Movement Example - Irrlicht Engine [");
tmp += driver->getName();
tmp += L"] fps: ";
tmp += fps;
device->setWindowCaption(tmp.c_str());
lastFPS = fps;
}
}
/*
In the end, delete the Irrlicht device.
*/
device->drop();
return 0;
}
示例5: main
/*
The event receiver for keeping the pressed keys is ready, the actual responses
will be made inside the render loop, right before drawing the scene. So lets
just create an irr::IrrlichtDevice and the scene node we want to move. We also
create some other additional scene nodes, to show that there are also some
different possibilities to move and animate scene nodes.
*/
int main()
{
// ask user for driver
video::E_DRIVER_TYPE driverType=driverChoiceConsole();
if (driverType==video::EDT_COUNT)
return 1;
// create device
MyEventReceiver receiver;
IrrlichtDevice* device = createDevice(driverType,
core::dimension2d<u32>(1280, 800), 16, false, false, false, &receiver);
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
/*
Create the node which will be moved with the WSAD keys. We create a
sphere node, which is a built-in geometry primitive. We place the node
at (0,0,30) and assign a texture to it to let it look a little bit more
interesting. Because we have no dynamic lights in this scene we disable
lighting for each model (otherwise the models would be black).
*/
scene::ISceneNode * node = smgr->addSphereSceneNode(EARTH_RADIUS, 36);
if (node)
{
node->setPosition(core::vector3df(0,0,30));
#ifdef _MSC_VER
node->setMaterialTexture(0, driver->getTexture("../../../src/vendor/irrlicht/media/wall.bmp"));
#else
node->setMaterialTexture(0, driver->getTexture("../../src/vendor/irrlicht/media/wall.bmp"));
#endif
node->setMaterialFlag(video::EMF_LIGHTING, false);
}
/*
To be able to look at and move around in this scene, we create a first
person shooter style camera and make the mouse cursor invisible.
*/
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
camera->setPosition(core::vector3df(0, 0, -EARTH_RADIUS * START_DISTANCE));
camera->setTarget(core::vector3df(0, 0, 0));
const f32 ONE_AU = 149597870.0f;
#if(0)
camera->setFarValue(ONE_AU);
#else
camera->setFarValue(2<<23);
#endif
device->getCursorControl()->setVisible(false);
/*
We have done everything, so lets draw it. We also write the current
frames per second and the name of the driver to the caption of the
window.
*/
int lastFPS = -1;
// In order to do framerate independent movement, we have to know
// how long it was since the last frame
u32 then = device->getTimer()->getTime();
// This is the movemen speed in units per second.
//#if(1)
const f32 MOVEMENT_SPEED = .5f;
//#else
//const f32 MOVEMENT_SPEED = EARTH_RADIUS;
//#endif
Skybox skybox(smgr, driver);
while(device->run())
{
// Work out a frame delta time.
const u32 now = device->getTimer()->getTime();
const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
then = now;
/* Check if keys W, S, A or D are being held down, and move the
sphere node around respectively. */
core::vector3df nodePosition = node->getPosition();
if(receiver.IsKeyDown(irr::KEY_KEY_W))
nodePosition.Y += MOVEMENT_SPEED * frameDeltaTime;
else if(receiver.IsKeyDown(irr::KEY_KEY_S))
nodePosition.Y -= MOVEMENT_SPEED * frameDeltaTime;
if(receiver.IsKeyDown(irr::KEY_KEY_A))
nodePosition.X -= MOVEMENT_SPEED * frameDeltaTime;
//.........这里部分代码省略.........
示例6: main
int main(int argc, char* argv[])
{
// ask user for driver
video::E_DRIVER_TYPE driverType=driverChoiceConsole();
if (driverType==video::EDT_COUNT)
return 1;
MyEventReceiver receiver;
IrrlichtDevice* device = createDevice(driverType,
core::dimension2du(800, 600), 32, false, false, false,
&receiver);
if(device == 0)
return 1;
IVideoDriver *driver = device->getVideoDriver();
ISceneManager *smgr = device->getSceneManager();
device->setWindowCaption(L"Irrlicht Example for SMesh usage.");
/*
Create the custom mesh and initialize with a heightmap
*/
TMesh mesh;
HeightMap hm = HeightMap(255, 255);
hm.generate(eggbox);
mesh.init(hm, 50.f, grey, driver);
// Add the mesh to the scene graph
IMeshSceneNode* meshnode = smgr -> addMeshSceneNode(mesh.Mesh);
meshnode->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
// light is just for nice effects
ILightSceneNode *node = smgr->addLightSceneNode(0, vector3df(0,100,0),
SColorf(1.0f, 0.6f, 0.7f, 1.0f), 500.0f);
if (node)
{
node->getLightData().Attenuation.set(0.f, 1.f/500.f, 0.f);
ISceneNodeAnimator* anim = smgr->createFlyCircleAnimator(vector3df(0,150,0),250.0f);
if (anim)
{
node->addAnimator(anim);
anim->drop();
}
}
ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
if (camera)
{
camera->setPosition(vector3df(-20.f, 150.f, -20.f));
camera->setTarget(vector3df(200.f, -80.f, 150.f));
camera->setFarValue(20000.0f);
}
/*
Just a usual render loop with event handling. The custom mesh is
a usual part of the scene graph which gets rendered by drawAll.
*/
while(device->run())
{
if(!device->isWindowActive())
{
device->sleep(100);
continue;
}
if(receiver.IsKeyDown(irr::KEY_KEY_W))
{
meshnode->setMaterialFlag(video::EMF_WIREFRAME, !meshnode->getMaterial(0).Wireframe);
}
else if(receiver.IsKeyDown(irr::KEY_KEY_1))
{
hm.generate(eggbox);
mesh.init(hm, 50.f, grey, driver);
}
else if(receiver.IsKeyDown(irr::KEY_KEY_2))
{
hm.generate(moresine);
mesh.init(hm, 50.f, yellow, driver);
}
else if(receiver.IsKeyDown(irr::KEY_KEY_3))
{
hm.generate(justexp);
mesh.init(hm, 50.f, yellow, driver);
}
driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(0xff000000));
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
示例7: main
/*
We create an irr::IrrlichtDevice and the scene nodes. One occluder, one
occluded. The latter is a complex sphere, which has many triangles.
*/
int main()
{
// ask user for driver
video::E_DRIVER_TYPE driverType=driverChoiceConsole();
if (driverType==video::EDT_COUNT)
return 1;
// create device
MyEventReceiver receiver;
IrrlichtDevice* device = createDevice(driverType,
core::dimension2d<u32>(640, 480), 16, false, false, false, &receiver);
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();
smgr->getGUIEnvironment()->addStaticText(L"Press Space to hide occluder.", core::recti(10,10, 200,50));
/*
Create the node to be occluded. We create a sphere node with high poly count.
*/
scene::ISceneNode * node = smgr->addSphereSceneNode(10, 64);
if (node)
{
node->setPosition(core::vector3df(0,0,60));
node->setMaterialTexture(0, driver->getTexture(mediaPath + "wall.bmp"));
node->setMaterialFlag(video::EMF_LIGHTING, false);
}
/*
Now we create another node, the occluder. It's a simple plane.
*/
scene::ISceneNode* plane = smgr->addMeshSceneNode(smgr->addHillPlaneMesh(
"plane", core::dimension2df(10,10), core::dimension2du(2,2)), 0, -1,
core::vector3df(0,0,20), core::vector3df(270,0,0));
if (plane)
{
plane->setMaterialTexture(0, driver->getTexture(mediaPath + "t351sml.jpg"));
plane->setMaterialFlag(video::EMF_LIGHTING, false);
plane->setMaterialFlag(video::EMF_BACK_FACE_CULLING, true);
}
/*
Here we create the occlusion query. Because we don't have a plain mesh scene node
(ESNT_MESH or ESNT_ANIMATED_MESH), we pass the base geometry as well. Instead,
we could also pass a simpler mesh or the bounding box. But we will use a time
based method, where the occlusion query renders to the frame buffer and in case
of success (occlusion), the mesh is not drawn for several frames.
*/
driver->addOcclusionQuery(node, ((scene::IMeshSceneNode*)node)->getMesh());
/*
We have done everything, just a camera and draw it. We also write the
current frames per second and the name of the driver to the caption of the
window to examine the render speedup.
We also store the time for measuring the time since the last occlusion query ran
and store whether the node should be visible in the next frames.
*/
smgr->addCameraSceneNode();
int lastFPS = -1;
u32 timeNow = device->getTimer()->getTime();
bool nodeVisible=true;
while(device->run())
{
plane->setVisible(!receiver.IsKeyDown(irr::KEY_SPACE));
driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,113,113,133));
/*
First, we draw the scene, possibly without the occluded element. This is necessary
because we need the occluder to be drawn first. You can also use several scene
managers to collect a number of possible occluders in a separately rendered
scene.
*/
node->setVisible(nodeVisible);
smgr->drawAll();
smgr->getGUIEnvironment()->drawAll();
/*
Once in a while, here every 100 ms, we check the visibility. We run the queries,
update the pixel value, and query the result. Since we already rendered the node
we render the query invisible. The update is made blocking, as we need the result
immediately. If you don't need the result immediately, e.g. because you have other
things to render, you can call the update non-blocking. This gives the GPU more
time to pass back the results without flushing the render pipeline.
If the update was called non-blocking, the result from getOcclusionQueryResult is
either the previous value, or 0xffffffff if no value has been generated at all, yet.
The result is taken immediately as visibility flag for the node.
*/
if (device->getTimer()->getTime()-timeNow>100)
//.........这里部分代码省略.........
示例8: main
//.........这里部分代码省略.........
false, false);
/*
Main loop
*/
bool first_loop_after_window_activation = true;
s32 lastFPS = -1;
// Time is in milliseconds
u32 lasttime = device->getTimer()->getTime();
while(device->run())
{
/*
Time difference calculation
*/
u32 time = device->getTimer()->getTime();
f32 dtime; // in seconds
if(time > lasttime)
dtime = (time - lasttime) / 1000.0;
else
dtime = 0;
lasttime = time;
updateViewingRange(dtime);
// Collected during the loop and displayed
core::list< core::aabbox3d<f32> > hilightboxes;
/*
Special keys
*/
if(receiver.IsKeyDown(irr::KEY_ESCAPE))
{
break;
}
/*
Player speed control
*/
v3f move_direction = v3f(0,0,1);
move_direction.rotateXZBy(camera_yaw);
v3f speed = v3f(0,0,0);
if(receiver.IsKeyDown(irr::KEY_KEY_W))
{
speed += move_direction;
}
if(receiver.IsKeyDown(irr::KEY_KEY_S))
{
speed -= move_direction;
}
if(receiver.IsKeyDown(irr::KEY_KEY_A))
{
speed += move_direction.crossProduct(v3f(0,1,0));
}
if(receiver.IsKeyDown(irr::KEY_KEY_D))
{
speed += move_direction.crossProduct(v3f(0,-1,0));
}
if(receiver.IsKeyDown(irr::KEY_SPACE))
{
if(player->touching_ground){
//player_speed.Y = 30*BS;
示例9: main
//.........这里部分代码省略.........
#if 1
ISGPObject* pObj0 = renderdevice->GetWorldSystemManager()->createObject(
String(L"StaticMesh\\jianzhu.mf1"),
String(L"SceneObject01"),
Vector3D(45.0f, 30.0f, 28.0f) );
pObj0->m_fScale = 1.5f;
pObj0->m_fRotationXYZ[1] = 45.0f * pi_over_180;
renderdevice->GetWorldSystemManager()->addSceneObject(pObj0);
#endif
ptestModel->setPosition(13.55f, renderdevice->GetWorldSystemManager()->getRealTerrainHeight(13.55f,3.55f), 3.55f);
//ptestModel->setScale(5.0f);
ptestModel->setVisible(true);
// Create other render to frame buffer
CSGPWorldConfig::getInstance()->m_bPostFog = true;
renderdevice->createRenderToFrameBuffer( viewarea.Width, viewarea.Height, false );
// In order to do framerate independent movement, we have to know
// how long it was since the last frame
device->setWindowCaption(L"SGP Engine - Test Sample Demo");
uint32 LastXPos = receiver.getXPosition();
uint32 LastYPos = receiver.getYPosition();
double averageMS = 0;
double averageFPS = 0;
while(device->run() && renderdevice)
{
if(receiver.IsKeyDown(KEY_F1))
{
static int mmmm = 0;
if( mmmm == 0)
{
String WorldMapName = String(L"worldmap\\") + renderdevice->GetWorldSystemManager()->getWorldName() + String(L".map");
renderdevice->GetWorldSystemManager()->saveWorldToFile(WorkingDir, WorldMapName);
mmmm++;
}
}
if(receiver.IsKeyDown(KEY_F3))
{
static int gg = 0;
if( gg == 0 )
{
renderdevice->GetWorldSystemManager()->setHeightMap(8, 119, 80);
renderdevice->GetWorldSystemManager()->setHeightMap(8, 120, 80);
uint32 chunks[4] = {224, 225, 240, 241};
renderdevice->GetWorldSystemManager()->flushTerrainHeight(chunks, 4);
renderdevice->GetWorldSystemManager()->setTerrainChunkLayerTexture(240, eChunk_Diffuse1Texture, String(L"Texture\\terrain\\dirt004.dds"));
renderdevice->GetWorldSystemManager()->setTerrainChunkLayerTexture(240, eChunk_Diffuse2Texture, String(L"Texture\\terrain\\dirt002.dds"));
renderdevice->GetWorldSystemManager()->setTerrainChunkLayerTexture(240, eChunk_Diffuse3Texture, String(L"Texture\\terrain\\stone001.dds"));
renderdevice->GetWorldSystemManager()->setTerrainChunkLayerTexture(240, eChunk_NormalMapTexture, String(L"Texture\\terrain\\normal001.dds"));
renderdevice->GetWorldSystemManager()->setTerrainChunkLayerTexture(240, eChunk_DetailMapTexture, String(L"Texture\\terrain\\detailmap001.dds"));
renderdevice->GetWorldSystemManager()->setTerrainChunkLayerTexture(240, eChunk_SlopeMapTexture, String(L"Texture\\terrain\\slope.dds"));
gg++;
}
uint32* pRawAlphaData = renderdevice->GetWorldSystemManager()->getWorldMap()->m_WorldChunkAlphaTextureData;
示例10: main
//.........这里部分代码省略.........
drv->beginScene();
switch (state) {
case MLAA_OFF:
if (showpic) def->Render(false);
else smgr->drawAll();
break;
case MLAA_ON:
if (showpic) def->Render(rt1);
else {
drv->setRenderTarget(rt1);
smgr->drawAll();
}
glClear(GL_STENCIL_BUFFER_BIT);
glStencilFunc(GL_ALWAYS, 1, ~0);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
sq->Render(rt2);
glStencilFunc(GL_EQUAL, 1, ~0);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
sq2->Render(rt3);
drv->setRenderTarget(rt1, false, false);
// Overlay the smoothed edges on the initial image
sq3->Render(false);
// Blit the final image to the framebuffer
glStencilFunc(GL_ALWAYS, 1, ~0);
norm->Render();
break;
}
drv->endScene();
if (state == MLAA_ON) {
gettimeofday(&tick2, NULL);
if (!firstrun) {
tmplong = (tick2.tv_sec - tick1.tv_sec) * 10000;
tmplong += (tick2.tv_usec - tick1.tv_usec) / 100;
fxtimer += tmplong;
onframes++;
} else {
firstrun = 0;
glsltime = tick2.tv_sec - tick1.tv_sec;
glsltime += (tick2.tv_usec - tick1.tv_usec) / 1000000.0;
}
}
int fps = drv->getFPS();
if (minfps > fps) minfps = fps;
if (lastfps != fps) {
swprintf(cap, 20, L"%d fps, MLAA %s", fps, state == MLAA_ON ? "on" : "off");
dev->setWindowCaption(cap);
lastfps = fps;
}
if (r->IsKeyDown(KEY_KEY_M)) {
if (state == MLAA_ON) state = MLAA_OFF;
else state = MLAA_ON;
lastfps++;
}
usleep(1); // 16?
total_frames++;
}
dev->drop();
delete ncb;
delete bcb;
delete def;
delete sq;
delete sq2;
delete sq3;
delete norm;
delete r;
struct timeval endtime;
gettimeofday(&endtime, NULL);
float sec = endtime.tv_sec - starttime.tv_sec;
sec += ((float) endtime.tv_usec - starttime.tv_usec) / 1000000;
printf("\nRan %.3fs, ", sec);
sec -= glsltime;
printf("average fps %.2f, min %d\n", (float) total_frames/sec, minfps);
if (onframes) {
printf("\nAverage on fps %.2f, average off fps %.2f\n\n", (float) onframes/(fxtimer/10000.0),
(float) (total_frames - onframes)/(sec - (fxtimer/10000.0)));
// printf("MLAA took on average %.1fms\n", (float) (fxtimer / onframes) / 10.0);
}
return 0;
}
示例11: main
//.........这里部分代码省略.........
m_iPlaneIndices[3] = 0;
m_iPlaneIndices[4] = 3;
m_iPlaneIndices[5] = 2;
SMaterial m_cRenderMaterial;
m_cRenderMaterial.Wireframe = false;
m_cRenderMaterial.Lighting = false;
m_cRenderMaterial.TextureLayer[0].TextureWrapU = irr::video::ETC_CLAMP;
m_cRenderMaterial.TextureLayer[0].TextureWrapV = irr::video::ETC_CLAMP;
ITexture *m_pRenderTexture = 0;
CvCapture *capture;
IplImage *frame;
char AviFileName[]="Accel World.mp4";
capture = cvCaptureFromAVI(AviFileName);
if (driver->queryFeature(irr::video::EVDF_RENDER_TO_TARGET))
{
m_pRenderTexture = driver->addRenderTargetTexture(irr::core::dimension2d<irr::u32>((irr::u32)(720), (irr::u32)(480)));
m_cRenderMaterial.setTexture(0, m_pRenderTexture);
}
// m_pRenderTexture = driver->getTexture("wall.bmp");
// m_cRenderMaterial.setTexture(0, m_pRenderTexture);
while(device->run())
{
const u32 now = device->getTimer()->getTime();
const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
then = now;
if(receiver.IsKeyDown(irr::KEY_KEY_W))
camshift.Z -= MOVEMENT_SPEED * frameDeltaTime;
else if(receiver.IsKeyDown(irr::KEY_KEY_S))
camshift.Z += MOVEMENT_SPEED * frameDeltaTime;
if(receiver.IsKeyDown(irr::KEY_KEY_A))
camshift.X -= MOVEMENT_SPEED * frameDeltaTime;
else if(receiver.IsKeyDown(irr::KEY_KEY_D))
camshift.X += MOVEMENT_SPEED * frameDeltaTime;
if(receiver.IsKeyDown(irr::KEY_KEY_X))
camshift.Y -= MOVEMENT_SPEED * frameDeltaTime;
else if(receiver.IsKeyDown(irr::KEY_SPACE))
camshift.Y += MOVEMENT_SPEED * frameDeltaTime;
cam->setPosition(camPos + camshift);
driver->beginScene(true, true, SColor(255,0,0,0));
driver->setRenderTarget(m_pRenderTexture, true, true, irr::video::SColor(0,0,0,0));
if(cvGrabFrame(capture))
{
frame=cvRetrieveFrame(capture);
void* pBits = m_pRenderTexture->lock();
u32 Pitch = m_pRenderTexture->getPitch();
int wmin= Pitch;
示例12: main
int main(int argc, const char** argv)
{
/* - deviceType: Type of the device. This can currently be the Null-device,
one of the two software renderers, D3D8, D3D9, or OpenGL. In this
example we use EDT_SOFTWARE, but to try out, you might want to
change it to EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D8,
EDT_DIRECT3D9, or EDT_OPENGL.
*/
MyEventReceiver receiver;
ISoundEngine* music = createIrrKlangDevice();
IrrlichtDevice *device =
createDevice( EDT_DIRECT3D9, dimension2d<u32>(640, 480), 32,
false, false, false, &receiver);
music->play2D("../media/MUSIC/Dark Impetus.mp3",true,false,true);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
ICameraSceneNode *camera = smgr->addCameraSceneNode();
IGUIFont* font = device->getGUIEnvironment()->getFont("../media/fonthaettenschweiler.bmp");
camera->setFarValue(900);
IAnimatedMesh* map = smgr->getMesh(DC_01);
IAnimatedMeshSceneNode* mapnode = smgr->addAnimatedMeshSceneNode(map);
mapnode->setMaterialFlag(EMF_LIGHTING,false);
IAnimatedMesh* player1 = smgr->getMesh(SORA);
IAnimatedMeshSceneNode* p1node = smgr->addAnimatedMeshSceneNode(player1);
p1node->setMaterialFlag(EMF_LIGHTING, false);
p1node->setScale(SORA_VECTOR3D);
IAnimatedMesh* player2 = smgr->getMesh(AQUA);
IAnimatedMeshSceneNode* p2node = smgr->addAnimatedMeshSceneNode(player2);
p2node->setMaterialFlag(EMF_LIGHTING, false);
p2node->setScale(NORMAL_VECTOR3D);
vector3df Position = p1node->getPosition();
vector3df P2Pos = p2node->getPosition();
vector3df PosCam = p1node->getPosition();
vector3df Rotate = p1node->getPosition();
int CurrentHP = 300;
int MaxHP = 400;
int HeartP = 10;
bool LockOn = false;
bool LockCheck = false;
stringw CoorCheck;
while(device->run())
{
CoorCheck +=L"Your position\nX:";
CoorCheck +=Position.X;
CoorCheck +=L"\nY:";
CoorCheck +=Position.Y;
CoorCheck +=L"\nZ:";
CoorCheck +=Position.Z;
CoorCheck +=L"\n\nTarget Position:";
CoorCheck +=P2Pos.X;
if(LockCheck != true){
if(receiver.IsKeyDown(KEY_KEY_J)){LockOn = true; LockCheck = true;}}
else{
if(receiver.IsKeyDown(KEY_KEY_J)){LockOn = false;LockCheck = false;}}
//3D Rendering.
MaximizeKey(receiver,device);
GetCaption(driver,device);
driver->beginScene(true, true, SColor(255,100,101,140));
p1node->setPosition(Position);
camera->setPosition(vector3df(PosCam.X,PosCam.Y+2,PosCam.Z+3));
if(LockOn != false){camera->setTarget(P2Pos);}
else{camera->setTarget(Position);}
smgr->drawAll();
//2D Rendering.
if(CurrentHP<=0){font->draw(L"You are dead!!!",rect<s32>(120,140,250,210),SColor(255,255,255,255));}
else{if(receiver.IsKeyDown(KEY_KEY_L)){--CurrentHP;}}
if(CurrentHP>=MaxHP){}else{if(receiver.IsKeyDown(KEY_KEY_K)){++CurrentHP;}}
if(receiver.IsKeyDown(KEY_KEY_N)){++MaxHP;}
if(receiver.IsKeyDown(KEY_KEY_M) && CurrentHP<MaxHP){--MaxHP;}
if(HeartP>=86){}else{
if(receiver.IsKeyDown(KEY_KEY_F)){++HeartP;}}
font->draw
(L"Press O for full screen.\nPress Up-Down-Left-right to move.\nPress L to hurt the character.\nPress K to heal the character.\nPress N to increase Max HP.\nPress M to decrease Max HP.\nPress F to fill the Heart gauge.",rect<s32>(20,40,150,110),SColor(255,0,0,0));
font->draw(CoorCheck,rect<s32>(20,140,150,110),SColor(255,0,0,0));
//Button detection.
if(receiver.IsKeyDown(KEY_UP)){
Position.Z -= 0.1f;
PosCam.Z = Position.Z;
p1node->setRotation(vector3df(Rotate.X,Rotate.Y = 0,Rotate.Z));
p1node->setPosition(Position);}
if(receiver.IsKeyDown(KEY_DOWN)){
Position.Z += 0.1f;
PosCam.Z = Position.Z;
p1node->setRotation(vector3df(Rotate.X,Rotate.Y -180,Rotate.Z));
p1node->setPosition(Position);}
if(receiver.IsKeyDown(KEY_LEFT)){
//.........这里部分代码省略.........
示例13: main
int main()
{
// Initialization of Device, Video Driver and Scene Manager
video::E_DRIVER_TYPE driverType=video::EDT_OPENGL;
MyEventReceiver receiver;
IrrlichtDevice* device = createDevice(driverType,
core::dimension2d<u32>(960, 720), 16, false, false, false, &receiver);
if (device == 0) return 1;
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
// Building the scene.
// open level file
ifstream infile;
infile.open("enigma3d.app/Contents/Resources/field.lvl");
if (infile.fail()) error("Could not open level file\n");
// checking the file starts with "Enigma-3D"
string line;
infile >> line;
if (line!="Enigma-3D") error("Illegal Level file: "+line+"\n");
// Playground is a two-dimensional array of pointers to fields:
Field * playground[dimx][dimy];
// now reading from level file one number for each field
// and creating a wall or floor of the appropriate sub-class
for(int j=0; j<dimy; j++){
for(int i=0; i<dimx; i++){
// determine filed type
int fieldtype;
infile >> fieldtype;
playground[i][j]=makefield(fieldtype,smgr,driver,i,j,playground);
}
}
// the level file may contain additional requests for introducing
// some fields to each other:
while ((infile >> line), line!="end"){
// must have the form "introduce x1 y1 to x1 y2"
if (line!="introduce") error("Level File: mistake in introduce lines");
int x1,x2,y1,y2;
infile >> x1 >> y1 >> line >> x2 >> y2;
if ( (x1 < 0) || x1>=dimx
|| (x2 < 0) || x2>=dimx
|| (y1 < 0) || y1>=dimy
|| (y2 < 0) || y2>=dimy
|| line !="to" )
error("Level File: mistake in introduce lines");
// call the introduceTo method of field x1 y1:
playground[x1][y1]->introduceTo(*(playground[x2][y2]));
}
infile.close();
Sphere *sphere=new Sphere(smgr,driver);
scene::ICameraSceneNode* camera=smgr->addCameraSceneNode(NULL,core::vector3df(offsety+50.f,100.f,offsetx),
core::vector3df(offsety,0.f,offsetx));
// to change the camera position use:
// camera->setPosition(core::vector3df(...));
// see docmentation of ICameraSceneNode for more (like setting target, rotation, aspect)
// hide the mouse cursor
device->getCursorControl()->setVisible(false);
// for time measurement: get an initial time reference
u32 then = device->getTimer()->getTime();
// for mouse-move measurement: get an initial mouse position
core::position2di RefPosition=receiver.Position;
// compute the field number where the sphere is and notify that field
int fieldx=getFieldx(sphere->getPosition());
int fieldy=getFieldy(sphere->getPosition());
playground[fieldx][fieldy]->sphereEnter(*sphere);
// Running function introduceSphere for every wall/floor ONCE
for(int j=0; j<dimy; j++)
for(int i=0; i<dimx; i++)
playground[i][j]-> introduceSphere(*sphere);
while(device->run())
{
if(receiver.IsKeyDown(irr::KEY_KEY_Q)) exit(0); // quit game on key Q
// Adapt speed by the difference in mouse position
core::position2di mousemove;
mousemove.X=(receiver.Position.X-RefPosition.X);
mousemove.Y=(receiver.Position.Y-RefPosition.Y);
// eliminating too rapid movements of the mouse
if (fabs((float)mousemove.X)>10) mousemove.X=0;
if (fabs((float)mousemove.Y)>10) mousemove.Y = 0;
// remember current mouse position
RefPosition=receiver.Position;
// Measure the time that has passed since last round
const u32 now = device->getTimer()->getTime();
//.........这里部分代码省略.........
示例14: main
int main()
{
scene::IMesh* testMesh;
scene::IMeshSceneNode* testNode;
scene::ITriangleSelector* selector;
core::matrix4 matrix = core::matrix4();
scene::ICameraSceneNode* camera;
core::vector3df cameraOffset = core::vector3df( 0.0f, 2.0f, 0.0f );
MyEventReceiver receiver;
IrrlichtDevice* device = createDevice( video::EDT_OPENGL,
core::dimension2du( 800, 600 ), 32, false, true, false,
&receiver );
if ( device == 0 ) exit( 1 );
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
scene::IMeshManipulator* meshManipulator = smgr->getMeshManipulator();
scene::ISceneCollisionManager* colliman = smgr->getSceneCollisionManager();
// load, scale and place mesh
driver->setTransform( video::ETS_WORLD, core::matrix4() );
testMesh = meshManipulator->createMeshCopy(
smgr->getMesh( "just_a_mesh.3ds" ) );
matrix.setScale( core::vector3df(
200.0f + 0.001f, 200.0f, 200.0f + 0.001f ) );
matrix.setTranslation(
core::vector3df(
99 * 400.0f + 200.0f,
0.0f,
99 * 400.0f + 200.0f
)
);
meshManipulator->transform( testMesh, matrix );
meshManipulator->recalculateNormals( testMesh, true );
// setHardwareMappingHint
for ( register u32 i = 0; i < testMesh->getMeshBufferCount(); ++i )
{
scene::IMeshBuffer* buffer = testMesh->getMeshBuffer( i );
buffer->setHardwareMappingHint( scene::EHM_STATIC );
buffer->setDirty();
buffer->recalculateBoundingBox();
}
// create node from mesh
testNode = smgr->addMeshSceneNode( testMesh );
testMesh->drop();
// set material
testNode->setMaterialTexture(
0, driver->getTexture( "just_a_texture.jpg" ) );
testNode->setMaterialType( video::EMT_SOLID );
testNode->setMaterialFlag( video::EMF_LIGHTING, false );
testNode->setVisible( true );
// add node to collision detection
selector = smgr->createOctreeTriangleSelector(
testNode->getMesh(), testNode, 900 );
testNode->setTriangleSelector( selector );
selector->drop();
// add a camera
camera = smgr->addCameraSceneNodeFPS( 0, 360.0f, 0.01f );
camera->setPosition( core::vector3df(39936.0f, 0.0f, 39755.0f) );
camera->setTarget( camera->getPosition() + core::vector3df( 1.0f, 0.0f, 1.0f ) );
camera->updateAbsolutePosition();
camera->setFarValue( 300.0f );
camera->setNearValue( 0.1f );
camera->setFOV( 1.25f );
camera->setAspectRatio( 4.0f / 3.0f );
camera->setInputReceiverEnabled( true );
smgr->setActiveCamera( camera );
device->getCursorControl()->setVisible( false );
while( device->run() )
{
if ( !device->isWindowActive() ) device->yield();
if ( receiver.IsKeyDown( irr::KEY_ESCAPE ) ) device->closeDevice();
core::vector3df pos = camera->getPosition() - cameraOffset;
pos.Y = getHeight( pos.X, pos.Z, colliman, testNode );
if ( pos.Y > 999.0f ) printf( "gap at x=%f, z=%f!\n", pos.X, pos.Z );
camera->setPosition( pos + cameraOffset );
driver->beginScene( true, true );
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
开发者ID:dixx,项目名称:getCollisionPointWithScalesMesh_Test,代码行数:92,代码来源:getCollisionPointWithScalesMesh_Test.cpp