Simple Camera Collides With Ground + Sky Dome
Posted: Mon Oct 01, 2007 12:25 am
Now First of the rotation of the models and positioning is up to you, i cannot provide mine. This code snippet basically allows the camera to walk across a base as if its ground, its very simple.
If you have any advice on the code I would like constructive criticisms.
Now A pic of the results:
[img]
http://img473.imageshack.us/my.php?imag ... ageqf6.jpg
[/img]
Code: Select all
/////////////////////////////////////
// Author: Dejai //
// Date: 1 Oct 2007 //
// Purpose: Tutorial / Rpg Base //
/////////////////////////////////
#include <irrlicht.h> // Declare Irrlicht
#include <iostream> // Add Iostream Common header not really needed for this tutorial
// Declare Using Namespace See Tutorial 1
using namespace irr;
using namespace core;
using namespace video;
using namespace scene;
using namespace io;
using namespace gui;
int main() // Start Int Main
{
// Start The Irrlicht Device Set driver, dimensions, resolution, colour depths,
// deside wether to enable fullscreen, shadowing and if to enable event reciver
IrrlichtDevice* device =
createDevice(EDT_OPENGL,dimension2d<s32>(600,480),16,
false, false , false, 0);
//Set The Window Caption to The Glade
device->setWindowCaption(L" The Glade ");
// Initialize the Drivers
IVideoDriver* driver = device->getVideoDriver(); // Initialize the Video Driver
ISceneManager* smgr = device->getSceneManager(); // Initialize the Scene Manager
IGUIEnvironment* guienv = device->getGUIEnvironment();// Initialize the GUI Environment
// Hide the cursor
device->getCursorControl()->setVisible(false);
// Add A Camera With FPS
ICameraSceneNode* camera = // Declar the camera
smgr->addCameraSceneNodeFPS();// Declare the pointer smgr( scene Manager) to add a FPS Camera.
// Start The Sky Done Declare Texture of Skydome, distance and strech
smgr->addSkyDomeSceneNode( driver->getTexture("media/sky.jpg"),16,
16, 1.0f, 2.0f);
////////////// MESH DECLARATION /////////////////////////////
// 1. Load The Base Map
IAnimatedMesh* base = smgr->getMesh("media/base.obj");
IAnimatedMeshSceneNode* base_node = smgr->addAnimatedMeshSceneNode(base);
if (base_node) // 1. Base Map Initialization
{
base_node->setMaterialFlag(EMF_LIGHTING, false); // Don't Have lighting
base_node->setMaterialTexture(0, driver->getTexture("media/grass.jpg"));// Choose a Texture
base_node->setPosition(vector3df(0,-10,0));// Set Position
base_node->setRotation(vector3df(90,180,180));// Set Rotation
base_node->setScale(vector3df(5,5,5));// Set Scale
}
// Triangle Selector
// Base
ITriangleSelector* base_selector = 0; // Declare Selector
base_selector = smgr->createOctTreeTriangleSelector(
base->getMesh(0), base_node, 128); // Declares which mesh and node it is assigned to
camera->setTriangleSelector(base_selector);// Sets the camera to the bass selector
base_selector->drop(); // Drop selector
// create collision response animator and attach it to the camera
ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
base_selector, camera, core::vector3df(60,100,60),
core::vector3df(-1,-1,-1), // This Sets Gravity VERY important, -1 keeps you grounded
core::vector3df(0,0,0));
camera->addAnimator(anim);// Canera add animatior
anim->drop();// drop animator
// End Of Base
while (device->run())// While Device is Running Do..
{
driver->beginScene(true, true, SColor(221,122,212,221));// Start The Scene
smgr->drawAll();// Draw all Scene Manager
guienv->drawAll();// Draw All Gui Environment
driver->endScene();// Driver End Scene
}
device->drop(); // Drop Device
return 0;// End
}
Now A pic of the results:
[img]
http://img473.imageshack.us/my.php?imag ... ageqf6.jpg
[/img]