Simple Camera Collides With Ground + Sky Dome

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

Simple Camera Collides With Ground + Sky Dome

Post by dejai »

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.

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
}
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]
Programming Blog: http://www.uberwolf.com
KakashiXP
Posts: 24
Joined: Mon Oct 08, 2007 4:38 pm
Location: a really big box
Contact:

Post by KakashiXP »

good work 8) i'll use it in my game :mrgreen:
remember kids, you are what you eat :-)
and... look everybody, its hitler buddy!

Image
KakashiXP
Posts: 24
Joined: Mon Oct 08, 2007 4:38 pm
Location: a really big box
Contact:

Post by KakashiXP »

you guys should really try modeling in blender!

it lets you test the level as a game Inside blender with a camera then Export it to a map file whatever so you dont have to wait for it to Remake the files...

and.

that game you have down there could be made in under 5 mins with blender... its not to hard to use...

right now im using Blender to make a music video :mrgreen:

You can do anything 3D With that thing 8)

JACINTO! Jack Into-
remember kids, you are what you eat :-)
and... look everybody, its hitler buddy!

Image
systat
Posts: 41
Joined: Mon Jan 07, 2008 8:01 pm

Post by systat »

How did you made such a nice flat terrain?
Post Reply