Crystal Space
Welcome, Guest. Please login or register.
September 30, 2014, 09:40:42 pm

Login with username, password and session length
Search:     Advanced search
9020 Posts in 2053 Topics by 8556 Members
Latest Member: Boshyeng
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  csRef<iPcLinearMovement>->SetFullPosition not placing the mesh correctly
« previous next »
Pages: [1] Print
Author Topic: csRef<iPcLinearMovement>->SetFullPosition not placing the mesh correctly  (Read 4995 times)
Panch
Jr. Member
**
Posts: 80


View Profile Email
« on: February 22, 2008, 12:32:06 am »

It doesn't place the mesh at the passed in csVector3, it doesn't always seem to place the mesh at the same miscalculation either.

Any ideas?
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #1 on: February 22, 2008, 05:43:11 am »

It doesn't place the mesh at the passed in csVector3, it doesn't always seem to place the mesh at the same miscalculation either.

Any ideas?

Hmm it should. Why do you think that it doesn't?

Greetings,
Logged
Panch
Jr. Member
**
Posts: 80


View Profile Email
« Reply #2 on: February 22, 2008, 01:39:16 pm »

Well I have a single map, then I load into another map and sector which for my intents is very similar to the same map. I basically want to be able to go to the same position in the new map/sector all the time, a fixed position.

But the SetFullPosition function doesn't do it. SetPosition seemed to move me to a point of: existing csVector3 + passed in csVector3, SetFullPosition seems to do the same.
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #3 on: February 22, 2008, 01:46:53 pm »

Well I have a single map, then I load into another map and sector which for my intents is very similar to the same map. I basically want to be able to go to the same position in the new map/sector all the time, a fixed position.

But the SetFullPosition function doesn't do it. SetPosition seemed to move me to a point of: existing csVector3 + passed in csVector3, SetFullPosition seems to do the same.

Can you show me the relevant source code?

Greetings,
Logged
Panch
Jr. Member
**
Posts: 80


View Profile Email
« Reply #4 on: February 22, 2008, 02:49:26 pm »

Sure Smiley

Code:
// Set up the application
bool Phage::Application()
{
    ...

if (!LoadLevel ("Phage1"))
    return ReportError ("Error loading level!");

   ...
}

Load the game level

Code:
// Load an initial game level
bool Phage::LoadLevel(csString level)
{
// Some flags to allow for 'in-game' movement and actions
LevelFlag = true;
StartCamFlag = false;
string levelName = "";
string libName = "";
string entitiesFile = "";
levelName = "/lev/" + level;
libName = "/lib/" + level;
    entitiesFile = level + "_entities";

const char* load_level = levelName.c_str ();
    const char* load_lib = libName.c_str ();
const char* load_entities = entitiesFile.c_str ();

#ifdef CS_DEBUG
Report (CS_REPORTER_SEVERITY_NOTIFY, "Attempting to load Map 1 level ...");
#endif

// Create the level entity
  level_entity = pl->CreateEntity ("level", bl, "level_behave",
    "pcworld.zonemanager",
    CEL_PROPCLASS_END);
  if (!level_entity)
    return ReportError ("Error creating level entity!");

  // Now get the iPcZoneManager interface so we can setup the level.
  csRef<iPcZoneManager> zonemgr = CEL_QUERY_PROPCLASS_ENT (level_entity,
  iPcZoneManager);
  iCelZone* zone = zonemgr->CreateZone ("main");
  iCelRegion* region = zonemgr->CreateRegion ("main");
  zone->LinkRegion (region);

  // Load the mapfile
  iCelMapFile* mapfile = region->CreateMapFile ();
  mapfile->SetPath (load_level);
  mapfile->SetFile ("world");

  // Load the entities file for the initial map
  iCelMapFile* entitiesfile = region->CreateMapFile ();
  entitiesfile->SetPath (load_lib);
  entitiesfile->SetFile (load_entities);

  return true;
}

Now in-line, while the game is running:
Code:
// Process the current frame
void Phage::ProcessFrame ()
{
   ...

if (phageKeyboard->randSteps == 50)
{
if (loadBattle)
{
loadBattle = false;
//battleFlag = true;
//MouseMove = false;
worldPos = playerMesh->GetMovable()->GetFullPosition();
LoadBattleLevel ("Battle1");
//MoveHero (csVector3(-42,.5,-82), "Scene2");
MoveHero (csVector3(2,2,15), "Scene2");
LoadBattle1Enemies ();
TransformBattle1Entities ();
}
...

}

Load the battle map:

Code:
// Load the battle map
bool Phage::LoadBattleLevel (csString level)
{
string levelName = "";
string libName = "";
string entitiesFile = "";
levelName = "/lev/" + level;
libName = "/lib/" + level;
    entitiesFile = level + "_entities";
// Some flags to allow for 'in-game' movement and actions
LevelFlag = true;
StartCamFlag = false;
loadBattle = false;

const char* load_level = levelName.c_str ();
const char* load_lib = libName.c_str ();
const char* load_entities = entitiesFile.c_str ();

#ifdef CS_DEBUG
Report (CS_REPORTER_SEVERITY_NOTIFY, "Attempting to load Map 1 Battle 1 level ...");
#endif

// Create an entity for the battle map
battle_entity = pl->CreateEntity ("level", bl, "level_behave",
    "pcworld.zonemanager",
    CEL_PROPCLASS_END);
if (!battle_entity)
return ReportError ("Error creating level entity!");

  // Create a 2nd iPcZoneManager interface so we can setup the battle map
  csRef<iPcZoneManager> battle_zonemgr = CEL_QUERY_PROPCLASS_ENT (battle_entity,
  iPcZoneManager);
  iCelZone* battle_zone = battle_zonemgr->CreateZone ("Battle");
  iCelRegion* battle_region = battle_zonemgr->CreateRegion ("Battle");
  battle_zone->LinkRegion (battle_region);

// Create and load the battle map
iCelMapFile* battle_mapfile = battle_region->CreateMapFile ();
battle_mapfile->SetPath (load_level);
battle_mapfile->SetFile ("world");

// Load the entities file for the initial map
// iCelMapFile* battle_entitiesfile = battle_region->CreateMapFile ();
// battle_entitiesfile->SetPath ("/lib/Phage1");
// battle_entitiesfile->SetFile ("Phage1_entities");

// Get the starting position within the new map and initialize the sector
CamStartPos();

return true;
}


And finally:

Code:
// Move the hero to the new sector/map
bool Phage::MoveHero(csVector3 destPos, csString destSector)
{
// Variables for being able to move sectors
float yrot;
iSector* sector;

loadMap = false;
    string destinationSector = destSector;
const char* destination = destinationSector.c_str ();
// Get the zone manager from the battle level entity
csRef<iPcZoneManager> pczonemgr = CEL_QUERY_PROPCLASS_ENT (battle_entity,
  iPcZoneManager);

// Set the camera to the new region in the battle map
pccamera->SetZoneManager(pczonemgr, true, "Battle", "Camera");

// Position our mesh in the new sector
csVector3 oldPos = pccamera->GetCamera()->GetTransform().GetOrigin();
pclinmove->GetLastPosition (oldPos, yrot, sector);
sector = engine->FindSector (destination);
pclinmove->SetFullPosition (destPos, yrot, sector);

return true;
}

It all works as it should, it just doesn't place the hero/camera at the "Full" position passed, i think its doing the interpolated position or whatever.

Any ideas?

Thanks!
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #5 on: February 22, 2008, 02:52:12 pm »

Well SetFullPosition() really doesn't do anything special. Certainly not interpolation. And this function is used (with no problems) in other projects. So I think something on your side is wrong but I can't immediatelly see what. Perhaps try with a debugger or printf to print out the values of the location that you pass to SetFullPosition(). That way you can see if they are really what you think they should be.

Greetings,
Logged
Panch
Jr. Member
**
Posts: 80


View Profile Email
« Reply #6 on: February 22, 2008, 06:50:05 pm »

Quote
Perhaps try with a debugger or printf to print out the values of the location that you pass to SetFullPosition()

Have already, everything is getting passed in right Sad

It shouldn't matter that I'm moving from 1 sector to another, as long as I measure the position in the new sector properly right?
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #7 on: February 22, 2008, 08:25:57 pm »

Perhaps give me the values that you pass along and what you get as a result (and also what you expect).

Greetings,
Logged
Panch
Jr. Member
**
Posts: 80


View Profile Email
« Reply #8 on: February 22, 2008, 09:04:32 pm »

Sure, this is the function call:
Code:
MoveHero (csVector3(2,2,15), "Scene2");

I basically expected the hero to show up at 2,2,15 in the new sector.
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #9 on: February 22, 2008, 09:29:09 pm »

Ok, and where does it end up instead? Details please!

Greetings,
Logged
Panch
Jr. Member
**
Posts: 80


View Profile Email
« Reply #10 on: February 22, 2008, 10:04:31 pm »

Sure Smiley

I end up in the new sector properly but at csVector3(2,1,-8); and it's not always at (2,1,-8). It seems like it varies upon where I am in the original sector.
« Last Edit: February 28, 2008, 08:43:52 pm by Panch » Logged
Panch
Jr. Member
**
Posts: 80


View Profile Email
« Reply #11 on: February 28, 2008, 08:46:31 pm »

Any idea?

Thanks Smiley
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #12 on: February 28, 2008, 09:15:01 pm »

What's the purpose of these two lines?

Code:
csVector3 oldPos = pccamera->GetCamera()->GetTransform().GetOrigin();
pclinmove->GetLastPosition (oldPos, yrot, sector);

Greetings,
Logged
Panch
Jr. Member
**
Posts: 80


View Profile Email
« Reply #13 on: February 29, 2008, 12:32:26 am »

Honestly I don't know, I got it from PlaneShift; removing it doesn't place the mesh at the passed in coordinates however Sad
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.683 seconds with 16 queries.