From: Brendon C. <br...@ch...> - 2007-10-20 08:06:02
|
Hi all, I am trying to get more familiar with CS + CEL and so have been making a number of modifications to the CEL walktut application. Something I am currently trying to do is to allow the user to shoot portals at the walls similar to that done in the games: Portal or Narbacular Drop. The idea is simple. There always exist two player located portals in the game located by something like a "portal gun". I.e. Left mouse button will perform a hit beam to locate the mesh that is hit and move portal A to that location, and right mouse button for portal B. Portals, A and B are always "connected". I.e. Looking and walking through A takes you to B and vice versa. I have most of what i want to achieve done, except the actual portals. My question is, how do i go about creating (in C++) two portals dynamically (I currently have them as entities but am having trouble making the mesh contain a portal)? I currently have two entities ("portal_a" and "portal_b") that have simple meshes (A box that is very thin, looks like a door) and am able to move them around the place using the users controls. What i dont seem to be able to do is to turn a single face of the box into a portal with a warp. Basically I wish to use something like the code below to define the mesh used by the entity for portal_a. Currently i assign from below the mesh: bmesh_a as the entities mesh. But it is not really working. After I have this i then realise that whenever i move the entities, I will also have to get a hold of the iPortal object and adjust the warp and dest sectors as necessary. I am not quite there yet though. Is someone able to look at below and give me any tips on how I can create this mesh with a portal for the front face? Also given the entity object, and querying the iPcMesh from it, how can i then get the iPortal object from that iPcMesh instance? Thanks. Brendon. // First create the factory: fact = engine->CreateMeshFactory ("crystalspace.mesh.object.genmesh", "cubeFact"); csRef<iGeneralFactoryState> factstate = scfQueryInterface< iGeneralFactoryState> (fact->GetMeshObjectFactory ()); factstate->GenerateBox(csBox3(csVector3(-1.0f, -1.0f, -0.1f), csVector3(1.0f, 2.0f, 0.1f))); factstate->CalculateNormals (); // Make a plane using the genmesh plug-in. bmesh_a = engine->CreateMeshWrapper (fact, "bmesh_a", start, csVector3 (0, 0, 0)); // Create a portal submesh the same as the front face of the box. csVector3 vertices[] = { csVector3(-1.0f, -1.0f, 0.1f), csVector3(-1.0f, 2.0f, 0.1f), csVector3( 1.0f, 2.0f, 0.1f), csVector3( 1.0f, -1.0f, 0.1f) }; iPortal* portal_a = NULL; csRef<iMeshWrapper> pmesh_a = engine->CreatePortal("portal_a", bmesh_a, start, vertices, 4, portal_a); |