From: Robin S. <ua...@us...> - 2004-03-28 23:40:06
|
Update of /cvsroot/once/oncecode/src/client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4773/oncecode/src/client Modified Files: ocdisplay.cpp ocdisplay.h ocentitymesh.cpp ocentitymesh.h Added Files: occltterrain.cpp occltterrain.h Log Message: Basic terrain generation and display on the client --- NEW FILE: occltterrain.h --- /* * occltterrain.h * Copyright (C) 2004 by Robin Stanton * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef OCCLTTERRAIN_H #define OCCLTTERRAIN_H #include "common/octerrain.h" #include "csutil/ref.h" class iMeshWrapper; /// Generates and manages a chunk of terrain that can be drawn class ocClientTerrainChunk : public ocTerrainChunk { protected: csRef<iMeshWrapper> mesh; public: ocClientTerrainChunk(int sizeX, int sizeY); virtual ~ocClientTerrainChunk(); virtual void Build(); virtual void SetPosition(csVector3 p); }; #endif // OCCLTTERRAIN_H Index: ocentitymesh.cpp =================================================================== RCS file: /cvsroot/once/oncecode/src/client/ocentitymesh.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ocentitymesh.cpp 20 Mar 2004 04:39:02 -0000 1.3 --- ocentitymesh.cpp 28 Mar 2004 23:28:45 -0000 1.4 *************** *** 24,27 **** --- 24,28 ---- #include "iengine/movable.h" #include "imap/parser.h" + #include "ocentitymesh.h" #include "occlient.h" Index: ocdisplay.h =================================================================== RCS file: /cvsroot/once/oncecode/src/client/ocdisplay.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** ocdisplay.h 6 Mar 2004 04:25:24 -0000 1.10 --- ocdisplay.h 28 Mar 2004 23:28:45 -0000 1.11 *************** *** 77,80 **** --- 77,81 ---- * must be */ void SetPlayer(ocID<ocPlayer> player); + ocID<ocPlayer> GetPlayer() {return player;} /** Return whether the player can move */ Index: ocentitymesh.h =================================================================== RCS file: /cvsroot/once/oncecode/src/client/ocentitymesh.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ocentitymesh.h 6 Mar 2004 04:25:24 -0000 1.1 --- ocentitymesh.h 28 Mar 2004 23:28:45 -0000 1.2 *************** *** 23,30 **** #include "csutil/ref.h" #include "common/ocentity.h" - #include "common/ocarea.h" class iMeshWrapper; - class iSector; /** --- 23,28 ---- Index: ocdisplay.cpp =================================================================== RCS file: /cvsroot/once/oncecode/src/client/ocdisplay.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** ocdisplay.cpp 20 Mar 2004 04:39:01 -0000 1.24 --- ocdisplay.cpp 28 Mar 2004 23:28:45 -0000 1.25 *************** *** 54,57 **** --- 54,61 ---- ocEntity *e = 0; /// *** ENTITY TEST *** + /// *** TERRAIN TEST *** + #include "occltterrain.h" + ocClientTerrainChunk *terr = 0; + /// *** TERRAIN TEST *** ocDisplay::ocDisplay() *************** *** 156,172 **** // Tell the camera to render into the frame buffer. view->Draw(); - /// *** ENTITY TEST *** - if (!e) - { - e = new ocEntity; - e->SetType("test"); - e->SetCurrentArea(ocAreaID(1)); - e->SetMesh(new ocEntityMesh(e)); - e->GetMesh()->SetPosition(player->GetAvatar()->GetPosition()); - } - /// *** ENTITY TEST *** if (outdated_files > 0) { /* FIXME: Draw a loading message here */ } } --- 160,186 ---- // Tell the camera to render into the frame buffer. view->Draw(); if (outdated_files > 0) { /* FIXME: Draw a loading message here */ + } else { + /// *** ENTITY TEST *** + if (!e && 0 /* disabled */) + { + e = new ocEntity; + e->SetType("test"); + e->SetCurrentArea(ocAreaID(1)); + e->SetMesh(new ocEntityMesh(e)); + e->GetMesh()->SetPosition(player->GetAvatar()->GetPosition()); + } + /// *** ENTITY TEST *** + + /// *** TERRAIN TEST *** + if (!terr) + { + terr = new ocClientTerrainChunk(32, 32); + terr->Build(); + terr->SetPosition(player->GetAvatar()->GetPosition()); + } + /// *** TERRAIN TEST *** } } --- NEW FILE: occltterrain.cpp --- /* * occltterrain.cpp * Copyright (C) 2004 by Robin Stanton * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "cssysdef.h" #include "csutil/objreg.h" #include "csutil/sysfunc.h" #include "iengine/mesh.h" #include "iengine/engine.h" #include "iengine/movable.h" #include "iengine/material.h" #include "iengine/texture.h" #include "imesh/genmesh.h" #include "imesh/object.h" #include "ivideo/txtmgr.h" #include "occlient.h" #include "ocdisplay.h" #include "occltterrain.h" #include "common/ocplayer.h" #include "common/ocentity.h" //------------------ ocClientTerrainChunk ----------------------------- ocClientTerrainChunk::ocClientTerrainChunk(int sizeX, int sizeY) : ocTerrainChunk(sizeX, sizeY) { } ocClientTerrainChunk::~ocClientTerrainChunk() { } void ocClientTerrainChunk::Build() { csRef<iEngine> engine = CS_QUERY_REGISTRY(clientsys->object_reg, iEngine); // Create material // **fix this** csString extended_name = "terrsnow.png"; csString vfsname = "/once/client/cache/1/" + extended_name; csRef<iTextureWrapper> txtwrap = engine->CreateTexture(extended_name, vfsname, 0, CS_TEXTURE_3D); assert(txtwrap); csRef<iMaterialWrapper> matwrap = engine->CreateMaterial(extended_name, txtwrap); assert(matwrap); // Make the height field first ocTerrainChunk::Build(); // Now for the mesh csPrintf("Creating terrain chunk (%i x %i)\n", hf.GetSizeX(), hf.GetSizeY()); // First create the factory: csRef<iMeshFactoryWrapper> fact = engine->CreateMeshFactory("crystalspace.mesh.object.genmesh", "terrchunkfact"); csRef<iGeneralFactoryState> factstate = SCF_QUERY_INTERFACE(fact->GetMeshObjectFactory(), iGeneralFactoryState); factstate->SetVertexCount(hf.GetSizeX() * hf.GetSizeY()); for (int y = 0, i = 0; y < hf.GetSizeY(); y++) for (int x = 0; x < hf.GetSizeX(); x++, i++) { factstate->GetVertices()[i].Set(x, hf(x,y), y); factstate->GetTexels()[i].Set(x / float(hf.GetSizeX()), y / float(hf.GetSizeY())); } factstate->SetTriangleCount((hf.GetSizeX() - 1) * (hf.GetSizeY() - 1) * 4); int v1 = 0, v2 = hf.GetSizeX(); for (int y = 0, i = 0; (y + 1) < hf.GetSizeY(); y++) { for (int x = 0; (x + 1) < hf.GetSizeX(); x++, v1++,v2++) { factstate->GetTriangles()[i++].Set(v1, v1+1, v2+1); factstate->GetTriangles()[i++].Set(v1, v2+1, v2); factstate->GetTriangles()[i++].Set(v1, v2+1, v1+1); factstate->GetTriangles()[i++].Set(v1, v2, v2+1); } v1 ++; v2 ++; } factstate->CalculateNormals(); // Now create an instance: mesh = engine->CreateMeshWrapper(fact, "terrchunk", clientsys->display->GetViewSector()); csRef<iGeneralMeshState> mesh_state = SCF_QUERY_INTERFACE(mesh->GetMeshObject(), iGeneralMeshState); mesh_state->SetMaterialWrapper(matwrap); mesh_state->SetLighting(false); mesh_state->SetShadowReceiving(false); csPrintf("Terrain Done\n"); engine->Prepare(); } void ocClientTerrainChunk::SetPosition(csVector3 p) { if (!mesh) return; iMovable *move = mesh->GetMovable(); if (!move) return; move->SetPosition(p); move->UpdateMove(); } |