Crystal Space
Welcome, Guest. Please login or register.
November 26, 2014, 11:31:31 am

Login with username, password and session length
Search:     Advanced search
9026 Posts in 2046 Topics by 9136 Members
Latest Member: Nataerb
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  A problem with hitbeam() and moving the world.
« previous next »
Pages: [1] Print
Author Topic: A problem with hitbeam() and moving the world.  (Read 3297 times)
Raymond Weijermars
Newbie
*
Posts: 4


View Profile Email
« on: June 08, 2006, 12:07:59 pm »

Hey,

I've been working on my first crystal space game for a school project for a while right now and until now its coming along nicely.
I've made a point and click control system for the game. While it works for the most part, my hitbeams seem to have a deviation after I've moved the world around.

I'm moving the world around for the camera control (using an isometric viewpoint). The problem is that after I've moved the world down the hitbeams seem to hit the world at a lower point then I click. The same happens when I move the world in another direction.

Has someone here had a similar problem? And if so, how can it be solved?

Thanks in advance.
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #1 on: June 08, 2006, 12:09:04 pm »

Hey,

I've been working on my first crystal space game for a school project for a while right now and until now its coming along nicely.
I've made a point and click control system for the game. While it works for the most part, my hitbeams seem to have a deviation after I've moved the world around.

I'm moving the world around for the camera control (using an isometric viewpoint). The problem is that after I've moved the world down the hitbeams seem to hit the world at a lower point then I click. The same happens when I move the world in another direction.

Has someone here had a similar problem? And if so, how can it be solved?

Thanks in advance.

What do you mean by 'moving the world'? Why not move the camera instead?

Greetings,
Logged
Raymond Weijermars
Newbie
*
Posts: 4


View Profile Email
« Reply #2 on: June 08, 2006, 12:16:54 pm »

Hey,

I've been working on my first crystal space game for a school project for a while right now and until now its coming along nicely.
I've made a point and click control system for the game. While it works for the most part, my hitbeams seem to have a deviation after I've moved the world around.

I'm moving the world around for the camera control (using an isometric viewpoint). The problem is that after I've moved the world down the hitbeams seem to hit the world at a lower point then I click. The same happens when I move the world in another direction.

Has someone here had a similar problem? And if so, how can it be solved?

Thanks in advance.

What do you mean by 'moving the world'? Why not move the camera instead?

Greetings,

Ah sorry, my mistake. I meant that we're moving the camera in world coordinates.
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #3 on: June 08, 2006, 12:20:13 pm »

I think I need to see code to see what is wrong.

Greetings,
Logged
Raymond Weijermars
Newbie
*
Posts: 4


View Profile Email
« Reply #4 on: June 08, 2006, 12:28:03 pm »

Ok, here is the code that we use when we move the camera. The moveBorder is set when you move the camera too the side of the screen.

void CameraView::draw(csTicks elapsed_time)
{
   if(moveBorder.right)
   {
      //CameraIsoLookat(views[current_view]);
      if(moveBorder.up)
      {
         //Move forward & right
         camera->MoveWorld (CS_VEC_FORWARD * CAMERA_SPEED * elapsed_time, false);
         camera->MoveWorld (CS_VEC_RIGHT * CAMERA_SPEED * elapsed_time, false);
         
      }
      else if(moveBorder.down)
      {
            //Move backward & right
         camera->MoveWorld (CS_VEC_BACKWARD * CAMERA_SPEED * elapsed_time, false);
         camera->MoveWorld (CS_VEC_RIGHT * CAMERA_SPEED * elapsed_time, false);
      }
      else
      {
         //Move right
         camera->MoveWorld (CS_VEC_RIGHT * CAMERA_SPEED * elapsed_time, false);
      }      
   }
   else if(moveBorder.left)
   {
      if(moveBorder.up)
      {
         //Move forward & left
         camera->MoveWorld (CS_VEC_FORWARD * CAMERA_SPEED * elapsed_time, false);
         camera->MoveWorld (CS_VEC_LEFT * CAMERA_SPEED * elapsed_time, false);
      }
      else if(moveBorder.down)
      {
            //Move backward & left
         camera->MoveWorld (CS_VEC_BACKWARD * CAMERA_SPEED * elapsed_time, false);
         camera->MoveWorld (CS_VEC_LEFT * CAMERA_SPEED * elapsed_time, false);
      }
      else{
            //Move left
         camera->MoveWorld (CS_VEC_LEFT * CAMERA_SPEED * elapsed_time, false);
      }
   }
   else if(moveBorder.up)
   {
      //Move forward
      camera->MoveWorld (CS_VEC_FORWARD * CAMERA_SPEED * elapsed_time, false);
      //camera->Move(CS_VEC_DOWN, false);
      
   }
   else if(moveBorder.down){
      //Move backward
      camera->MoveWorld (CS_VEC_BACKWARD * CAMERA_SPEED * elapsed_time, false);
      
      //camera->Move(CS_VEC_DOWN, false);
      //camera->Move(CS_VEC_UP, false);
      
   }
   // due to moving the camera so far away, depth buffer accuracy is
   // impaired, repair that by using smaller coordinate system
   view->Draw();
}


This is the method that we use too determine what point of the world you clicked on.

csVector3 CameraView::getWorldPoint(double x, double y)
{
   //The mouse (0,0) starts in upperleft corner while the g2d (0,0) starts in lowerleft corner
   //fix the y position
   csVector2 v2d(x, (float)(view->GetContext()->GetHeight() - y));
   csVector3 v3d;

   // First translate the mouse position to a 3d vector, aiming away from the camera origin.
   camera->InvPerspective(v2d, DEFAULT_Z_VALUE, v3d);

   //transform the camera 3d vector to a world vector
   clickedPoint = camera->GetTransform().This2OtherRelative(v3d);

   //Get the sector
   iSector* sector = view->GetCamera()->GetSector();
   //Get the origin of the camera in world position
   csVector3 origin = view->GetCamera()->GetTransform().GetOrigin();
   csVector3 isect;
   int sel;
   //Calculates the first position where a beam between origin and clickedPoint intersects the world.
   iMeshWrapper* mesh = sector->HitBeamPortals(origin, clickedPoint, isect, &sel);
   return isect;
}

Thanks for the help Smiley
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #5 on: June 08, 2006, 12:36:14 pm »

You should use This2Other() instead of This2OtherRelative(). The camera coordinate you get is not relative and you need an absolute point in world space.

Greetings,
Logged
Raymond Weijermars
Newbie
*
Posts: 4


View Profile Email
« Reply #6 on: June 08, 2006, 01:07:03 pm »

Thanks again. That did it Smiley.
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 6.4 seconds with 17 queries.