- - - -
void Simple::CreateRoom () {
if (!loader->LoadTexture ("wall", "/this/images/wall.png"))
ReportError ("Failed to load \"wall\" texture");
if (!loader->LoadTexture ("wooden_floor", "/this/images/wooden_floor.png"))
ReportError ("Failed to load \"wooden_floor\" texture");
if (!loader->LoadTexture ("ceiling", "/this/images/ceiling.png"))
ReportError ("Failed to load \"ceiling\" texture");
iMaterialWrapper *wall_mw = engine->GetMaterialList ()->FindByName ("wall");
iMaterialWrapper *wooden_floor_mw =
engine->GetMaterialList ()->FindByName ("wooden_floor");
iMaterialWrapper *ceiling_mw = engine->GetMaterialList ()->FindByName ("ceiling");
room = engine->CreateSector ("room");
/*csRef<iMeshWrapper>*/ walls = engine->CreateSectorWallsMesh (room, "walls");
csRef<csColliderWrapper> col_walls = csColliderHelper::InitializeCollisionWrapper
(cd_sys, walls);
csRef<iMeshObject> walls_object = walls->GetMeshObject ();
csRef<iMeshObjectFactory> walls_factory = walls_object->GetFactory ();
csRef<iThingFactoryState> wfs = scfQueryInterface<iThingFactoryState> (walls_factory);
//csRef<iThingState> ws = SCF_QUERY_INTERFACE (walls->GetMeshObject (), iThingState);
//csRef<iThingFactoryState> wfs = ws->GetFactory ();
wfs->AddInsideBox (
csVector3 (-10, 0, -10),
csVector3 (10, 10, 10)
);
// Texture mapping the walls
wfs->SetPolygonMaterial (csPolygonRange (0, 0), wall_mw);
wfs->SetPolygonTextureMapping (csPolygonRange (0, 0),
csVector2 (1, 1),
csVector2 (0, 1),
csVector2 (0, 0)
);
wfs->SetPolygonMaterial (csPolygonRange (1, 1), wall_mw);
wfs->SetPolygonTextureMapping (csPolygonRange (1, 1),
csVector2 (0, 1),
csVector2 (1, 1),
csVector2 (1, 0)
);
wfs->SetPolygonMaterial (csPolygonRange (2, 2), wall_mw);
wfs->SetPolygonTextureMapping (csPolygonRange (2, 2),
csVector2 (1, 1),
csVector2 (0, 1),
csVector2 (0, 0)
);
wfs->SetPolygonMaterial (csPolygonRange (3, 3), wall_mw);
wfs->SetPolygonTextureMapping (csPolygonRange (3, 3),
csVector2 (0, 1),
csVector2 (1, 1),
csVector2 (1, 0)
);
// Texture mapping the floor and the ceiling
wfs->SetPolygonMaterial (csPolygonRange (4, 4), wooden_floor_mw);
wfs->SetPolygonTextureMapping (csPolygonRange (4, 4),
csVector2 (1, 1),
csVector2 (0, 1),
csVector2 (0, 0)
);
wfs->SetPolygonMaterial (csPolygonRange (5, 5), ceiling_mw);
wfs->SetPolygonTextureMapping (csPolygonRange (5, 5),
csVector2 (1, 1),
csVector2 (1, 0),
csVector2 (0, 0)
);
if (!loader->LoadTexture ("ball_tex", "/this/images/grass_1_pre.jpg"))
ReportError ("Failed to load \"earth\" texture");
if (!loader->LoadTexture ("cube_tex", "/this/images/washing_machine.png"))
ReportError ("Failed to load \"cube\" texture");
iMaterialWrapper *cube_tex_mw = engine->GetMaterialList ()->FindByName ("cube_tex");
if (!loader->LoadTexture ("cube_tex_wall", "/this/images/washing_machine_wall.png"))
ReportError ("Failed to load \"cube wall\" texture");
iMaterialWrapper *cube_tex_wall_mw = engine->GetMaterialList ()->FindByName (
"cube_tex_wall");
iMaterialWrapper *earth_map_mw = engine->GetMaterialList ()->FindByName (
"ball_tex");
// It's training in using mesh obj and creating genmesh
fact = engine->CreateMeshFactory ("crystalspace.mesh.object.genmesh", "ball_fact"); csRef<iGeneralFactoryState> fact_state = scfQueryInterface<iGeneralFactoryState> (
fact->GetMeshObjectFactory ());
fact_state->GenerateSphere (csEllipsoid (csVector3 (0, 0, 0), csVector3 (1, 1, 1)), 50);
//cout << fact_state->GetTriangleCount () << endl;
fact_state->CalculateNormals ();
const int NUM_OF_BALLS = 20;
csRefArray<iMeshWrapper> array_of_balls (NUM_OF_BALLS);
csRefArray<iGeneralMeshState> array_of_ball_states (NUM_OF_BALLS);
for (int i = 0; i < NUM_OF_BALLS; i++) {
csRef<iMeshWrapper> tmp;
if (i < 10)
tmp = engine->CreateMeshWrapper (fact, "one_of_the_balls", room,
csVector3 (-2 * i + 9, 5, 5));
else
tmp = engine->CreateMeshWrapper (fact, "one_of_the_balls", room,
csVector3 (-2 * i + 29, 8, 5));
array_of_balls[i] = tmp;
csRef<iGeneralMeshState> ttmp;
ttmp = scfQueryInterface<iGeneralMeshState> (array_of_balls[i]->GetMeshObject ());
array_of_ball_states[i] = ttmp;
array_of_ball_states[i]->SetMaterialWrapper (earth_map_mw);
}
// It's training in using thing mesh obj
csRef<iMeshWrapper> cube = engine->CreateThingMesh (room, "cube");
csRef<iMeshObject> cube_object = cube->GetMeshObject ();
csRef<iMeshObjectFactory> cube_factory = cube_object->GetFactory ();
csRef<iThingFactoryState> cube_state = scfQueryInterface<iThingFactoryState> (
cube_factory);
cube_state->AddOutsideBox (csVector3 (7, 0, 7), csVector3 (9, 3, 9));
cube_state->SetPolygonMaterial (csPolygonRange (1, 5), cube_tex_wall_mw);
cube_state->SetPolygonTextureMapping (csPolygonRange (1, 5), 1);
cube_state->SetPolygonMaterial (csPolygonRange (0, 0), cube_tex_mw);
cube_state->SetPolygonTextureMapping (csPolygonRange (0, 0),
csVector2 (0, 0),
csVector2 (1, 0),
csVector2 (1, 1)
);
// It's training in moving a mesh
csRef<iMovable> cube_movable = cube->GetMovable ();
/*
csReversibleTransform empty_one;
empty_one.RotateThis (csVector3 (0, 1, 0), 0.7853);
cube_movable->SetTransform (cube_movable->GetTransform ().This2Other (
&csVector3 (0, 1, 0)));
*/
/*
cube_movable->GetTransform ().RotateThis (
cube_movable->GetTransform ().Other2This (csVector3 (0, 1, 0)), 0.7853);
*/
cube_movable->UpdateMove ();
// Add lights to be able to see something
csColliderHelper::InitializeCollisionWrappers (cd_sys, engine);
csRef<iLight> light;
iLightList *light_list = room->GetLights ();
light = engine->CreateLight (0, csVector3 (0, 8, 0), 50, csColor (1, 1, 1));
light_list->Add (light);
}
- - - -