Crystal Space
Welcome, Guest. Please login or register.
December 21, 2014, 01:58:12 pm

Login with username, password and session length
Search:     Advanced search
9032 Posts in 2046 Topics by 9297 Members
Latest Member: Adrihjapa
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  Help in heightmap
« previous next »
Pages: [1] Print
Author Topic: Help in heightmap  (Read 1859 times)
alcapique
Guest


Email
« on: July 16, 2005, 01:03:23 pm »

Hi

I want to use a heightmap in a small application to study how it work. So I modify the CS' simple1 tutorial but I got nothing, just a error message, something like "can´t load 'world' on VFS".
Look what a did:


#ifndef __SIMPLE_H__
#define __SIMPLE_H__

#include <stdarg.h>

struct iEngine;
struct iLoader;
struct iGraphics3D;
struct iKeyboardDriver;
struct iSector;
struct iView;
struct iVirtualClock;
struct iObjectRegistry;
struct iEvent;

class Simple
{
private:
  iObjectRegistry* object_reg;
  csRef<iEngine> engine;
  csRef<iLoader> loader;
  csRef<iGraphics3D> g3d;
  csRef<iKeyboardDriver> kbd;
  csRef<iVirtualClock> vc;
  csRef<iVFS> VFS; //I put this
  csRef<iView> view;

  static bool SimpleEventHandler (iEvent& ev);
  bool HandleEvent (iEvent& ev);
 
  void SetupFrame ();
  void FinishFrame ();
  float rotX, rotY;
 
public:
  Simple (iObjectRegistry* object_reg);
  ~Simple ();

  bool Initialize ();
  void Start ();
};

#endif // __SIMPLE1_H__

------------------------------------------------------------------------------------------------------------------------------

#include "csutil/cscolor.h"
#include "cstool/csview.h"
#include "cstool/initapp.h"
#include "teste.h"
#include "iutil/eventq.h"
#include "iutil/event.h"
#include "iutil/objreg.h"
#include "iutil/csinput.h"
#include "iutil/virtclk.h"
#include "iengine/sector.h"
#include "iengine/engine.h"
#include "iengine/camera.h"
#include "iengine/light.h"
#include "iengine/texture.h"
#include "iengine/mesh.h"
#include "iengine/movable.h"
#include "iengine/material.h"
#include "imesh/thing.h"
#include "imesh/object.h"
#include "ivideo/graph3d.h"
#include "ivideo/graph2d.h"
#include "ivideo/texture.h"
#include "ivideo/material.h"
#include "ivideo/fontserv.h"
#include "igraphic/imageio.h"
#include "imap/parser.h"
#include "ivaria/reporter.h"
#include "ivaria/stdrep.h"
#include "csutil/cmdhelp.h"
#include "csutil/event.h"

CS_IMPLEMENT_APPLICATION

// The global pointer to simple
Simple* simple = 0;

Simple::Simple (iObjectRegistry* object_reg)
{
  Simple::object_reg = object_reg;
}

Simple::~Simple ()
{
}

bool Simple::Initialize ()
{
  if (!csInitializer::RequestPlugins (object_reg,
        CS_REQUEST_VFS,
        CS_REQUEST_OPENGL3D,
        CS_REQUEST_ENGINE,
        CS_REQUEST_FONTSERVER,
        CS_REQUEST_IMAGELOADER,
        CS_REQUEST_LEVELLOADER,
        CS_REQUEST_REPORTER,
        CS_REQUEST_REPORTERLISTENER,
        CS_REQUEST_END))
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
        "crystalspace.application.simple",
        "Can't initialize plugins!");
    return false;
  }

  if (!csInitializer::SetupEventHandler(
  object_reg, SimpleEventHandler))
  {
   csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
      "crystalspace.application.simple",
      "Can't initialize event handler!");
   return false;
  }

  // Check for commandline help.
  if (csCommandLineHelper::CheckHelp (object_reg))
  {
    csCommandLineHelper::Help (object_reg);
    return false;
  }

  // The virtual clock.
  vc = CS_QUERY_REGISTRY (object_reg, iVirtualClock);
  if (!vc)
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
        "crystalspace.application.simple",
        "Can't find the virtual clock!");
    return false;
  }

  // Find the pointer to engine plugin
  engine = CS_QUERY_REGISTRY (object_reg, iEngine);
  if (!engine)
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
        "crystalspace.application.simple",
        "No iEngine plugin!");
    return false;
  }

  loader = CS_QUERY_REGISTRY (object_reg, iLoader);
  if (!loader)
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
        "crystalspace.application.simple",
        "No iLoader plugin!");
    return false;
  }

  g3d = CS_QUERY_REGISTRY (object_reg, iGraphics3D);
  if (!g3d)
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
        "crystalspace.application.simple",
        "No iGraphics3D plugin!");
    return false;
  }

  VFS = CS_QUERY_REGISTRY (object_reg, iVFS); // I put this
  if (!VFS)
  {
    csReport (object_reg,CS_REPORTER_SEVERITY_ERROR,
      "crystalspace.application.simple",
      "No iVFS plugin!");
    return false;
  }
 

  kbd = CS_QUERY_REGISTRY (object_reg, iKeyboardDriver);
  if (!kbd)
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
        "crystalspace.application.simple",
        "No iKeyboardDriver plugin!");
    return false;
  }

  // Open the main system. This will open all the previously
  // loaded plug-ins.
  if (!csInitializer::OpenApplication (object_reg))
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
        "crystalspace.application.simple",
        "Error opening system!");
    return false;
  }

  csReport (object_reg, CS_REPORTER_SEVERITY_NOTIFY,
        "crystalspace.application.simple",
        "Simple Crystal Space Application version 0.1.");

  VFS->ChDir ("data/terrain"); // I put this
  loader->LoadMapFile ("world");


  view = csPtr<iView> (new csView (engine, g3d));
  //view->GetCamera ()->SetSector (world);
  view->GetCamera ()->GetTransform ().SetOrigin (csVector3 (0, 5, -3));
  iGraphics2D* g2d = g3d->GetDriver2D ();
  view->SetRectangle (0, 0, g2d->GetWidth (), g2d->GetHeight ());

  engine->Prepare (); // I put this

  return true;
}

bool Simple::HandleEvent (iEvent& ev)
{
  if (ev.Type == csevKeyboard &&
    csKeyEventHelper::GetEventType (&ev) == csKeyEventTypeDown &&
    csKeyEventHelper::GetCookedCode (&ev) == CSKEY_ESC)
  {
    csRef<iEventQueue> q (CS_QUERY_REGISTRY (object_reg, iEventQueue));
    if (q)
      q->GetEventOutlet()->Broadcast (cscmdQuit);
    return true;
  }
  return false;
}

bool Simple::SimpleEventHandler (iEvent& ev)
{
  return simple ? simple->HandleEvent (ev) : false;
}

void Simple::Start ()
{
  csDefaultRunLoop (object_reg);
}

/*---------------*
 * Main function
 *---------------*/
int main (int argc, char* argv[])
{
  iObjectRegistry* object_reg =
    csInitializer::CreateEnvironment (argc, argv);
  if (!object_reg) return -1;

  simple = new Simple (object_reg);
  if (simple->Initialize ())
    simple->Start ();
  delete simple;
  simple = 0;

  csInitializer::DestroyApplication (object_reg);
  return 0;
}

Are there best, simple and easy way to use a heigthmap in a very simple application?

Logged
Vincent
Full Member
***
Posts: 191


View Profile WWW
« Reply #1 on: August 21, 2005, 10:16:53 pm »

(_snip_)
  VFS->ChDir ("data/terrain"); // I put this
  loader->LoadMapFile ("world");

(_snip)
Are there best, simple and easy way to use a heigthmap in a very simple application?

Assuming you want to load the existing terrain map provided with CS, you could use
VFS->ChDir ("/lev/terrain");
or
VFS->ChDir ("/this/data/terrain");
the former being cleaner.
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 4.166 seconds with 15 queries.