CopperCube
Computer Games
Development
Introduction
CopperCube is an editor to create 3D scenes
for Irrlicht.
It can be downloaded from www.ambiera.com
There is a commercial and a free version
We only need the free version
It continues to work even after the paid-for
version expires
It outputs Irrlicht scenes in .irr format (in reality an
XML format).
2
Setting Up
Copy
K:\Teaching Materials\CI\CI2510\DG\project
To
C:\apps
4
How will we use CopperCube
We will be creating 3D scenes in CopperCube,
and then importing them into our Irrlicht
game written in C++.
CopperCube has a number of built in prefabs.
You can use these in your own games (but
only the static ones).
You can import animated models into
CopperCube and position them.
5
Experiment
Load Irrlicht example 15
Compile and run it
A demo scene will be created
Experiment
The loaded scene is called example.irr
Locate this file on the system (in the irrlicht
media folder)
<?xml version="1.0"?>
<irr_scene>
<attributes>
<string name="Name" value="root" />
<int name="Id" value="-1" />
<vector3d name="Position" value="0.000000, 0.000000, 0.000000" />
<vector3d name="Rotation" value="0.000000, 0.000000, 0.000000" />
<vector3d name="Scale" value="1.000000, 1.000000, 1.000000" />
<bool name="Visible" value="true" />
<enum name="AutomaticCulling" value="box" />
<bool name="DebugDataVisible" value="false" />
<bool name="IsDebugObject" value="false" />
</attributes>
Example xml
describing the
scene.
This is from
example.irr
<userData>
<attributes>
<bool name="OccludesLight" value="false" />
</attributes>
</userData>
<node type="mesh">
Gravity
To add gravity to the demo scene:
/*
Now that the mesh scene nodes have had triangle selectors created and
added
to the meta selector, create a collision response animator from that meta
selector.
*/
scene::ISceneNodeAnimator* anim = smgr>createCollisionResponseAnimator(
meta, camera, core::vector3df(5,5,5),
core::vector3df(0,0,0));
Middle number needs to be changed e.g. to -10,
but depends on scale of scene
8
Experiment
In CopperCube, open the example sunset_flat:
File / New / Open Example Scene
Now export as an Irrlicht Scene. Call it
sunset_flat.irr
10
Creating your scene
Create your scene in CopperCube
Save your scene and in addition:
Export as File / export / export current scene
as Irrlicht Scene .irr
Save in some suitable location
11
Creating your scene
Check the file paths in your .irr file so that the
texture image locations are correct
Check the file paths in any mesh folders of the
textures. These mesh folders will have the
same name as what your called your .irr file.
You can use relative paths. You could shift all
textures into the same location. 12
When you run the scene you will notice that
the start position will be wrong. You need to
find the correct start location.
13
Camera Location
Make some edits so that the current location
of the camera is shown.
(code snippet shown on next page)
This code gets the X,Y,Z location of the camera
and puts it into a string.
This is then displayed at the very top of the
screen instead of the Frames Per Second (FPS)
previously shown
14
wchar_t tmp[1000];
int lastFPS = -1;
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(0,200,200,200));
smgr->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
swprintf(tmp, 1000, L"(%3.1f,%3.1f,%3.1f)", camera->getPosition().X,
camera->getPosition().Y, camera->getPosition().Z);
device->setWindowCaption(tmp);
lastFPS = fps;
15
Determining the start location
You now need to restart the program and
move around the scene until you find a good
start location.
Make a note of the three numbers at the top
of the screen.
16
Setting the start location
To set the start position of the camera use
camera->setPosition. There should already be
a line like this with the code. Change the
values to match your desired start location,
e.g.
camera>setPosition(core::vector3df(178.0f,1
17
67.0f,5.0f));
Setting the target
You also need to set what the camera is
pointing at. To begin with this will be
something in the distance at the same height
as the camera. This is achieved using camera>setTarget
camera->setTarget(core::vector3df(0.0f,167.0f,0.0f));
To begin with, just make the X and Z values
zero, then
18
Gravity + collisions
Now that the start location has been set you
can add gravity. You couldnt add it before
because you were in space to begin with and
you would have just fallen down into the void.
Gravity is set in the collision response
animator (discussed last week). Look for this
line in the code.
19
Gravity + collision
scene::ISceneNodeAnimator* anim = smgr>createCollisionResponseAnimator(
meta,
camera, core::vector3df(15,20,15), // this is how big you are. Middle number
is height, others are the width+breadth
core::vector3df(0,-3,0), // middle number is gravity
core::vector3df(0,15,0)); // the middle number is your head height
These numbers need to be adjusted to fit the scale of your scene.
Try climbing up the stairs.
20
Adjusting the camera
scene::ICameraSceneNode * camera = smgr>addCameraSceneNodeFPS(0, 50.f, 0.1f, 0, 0,
0, true, 0.3f);
21
Keyboard movement
We will now edit this example to adjust the
keys to the standard WSAD, and also include
jumping.
Replace the line containing
addCameraSceneNodeFPS with the code on
the following page to enable keyboard
movement.
22
Keyboard control
SKeyMap keyMap[9];
keyMap[0].Action = EKA_MOVE_FORWARD;
keyMap[0].KeyCode = KEY_UP;
keyMap[1].Action = EKA_MOVE_FORWARD;
keyMap[1].KeyCode = KEY_KEY_W;
keyMap[2].Action = EKA_MOVE_BACKWARD;
keyMap[2].KeyCode = KEY_DOWN;
keyMap[3].Action = EKA_MOVE_BACKWARD;
keyMap[3].KeyCode = KEY_KEY_S;
keyMap[4].Action = EKA_STRAFE_LEFT;
keyMap[4].KeyCode = KEY_LEFT;
keyMap[5].Action = EKA_STRAFE_LEFT;
keyMap[5].KeyCode = KEY_KEY_A;
keyMap[6].Action = EKA_STRAFE_RIGHT;
keyMap[6].KeyCode = KEY_RIGHT;
keyMap[7].Action = EKA_STRAFE_RIGHT;
keyMap[7].KeyCode = KEY_KEY_D;
keyMap[8].Action = EKA_JUMP_UP;
keyMap[8].KeyCode = KEY_KEY_J;
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 50.0f, .1f, -1, keyMap, 9, false, 0.3f);
23
Getting access to the scene nodes
There is an interesting snippet of code which
runs through the entire scene graph which can
be found in example 15.
Edit this code and modify it so it prints the
name, location, rotation and scale of every
element.
24
Tip: Finding a scenenode by name
It is possible to find a particular scene node by
name.
Once you have a pointer to the scene node
you can change its properties.
irr::scene::ISceneNode* node = smgr>getSceneNodeByName(const
irr::core::stringc& name);
25
Creating a 3d room
CopperCube has a feature where you can
draw a map of a room, and it will create the
3D room.
Select insert / create a room mesh from a 3d
map.
Draw your 3d map.
Export using File / Export / Export Current
Scene as Irrlicht Scene
Load into Irrlicht.
26
3d room from 2d map
27
scene::ISceneNode* node = smgr>getSceneNodeFromName("data");
if (!node)
cout << "node not found" << endl;
else
cout << "found it " << endl;
28