Crystal Space
Welcome, Guest. Please login or register.
November 27, 2014, 08:05:37 am

Login with username, password and session length
Search:     Advanced search
9026 Posts in 2046 Topics by 9141 Members
Latest Member: Corneliussummers
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Game Content Creation
| | |-+  attaching weapons to camera
« previous next »
Pages: [1] Print
Author Topic: attaching weapons to camera  (Read 4384 times)
phototrix
Newbie
*
Posts: 20


View Profile
« on: January 23, 2006, 08:49:12 am »

I'm constructing a tiny first-person-shooter and am trying to get the current weapon displayed on the screen such that it moves with the camera movement - ala half-life, doom, etc. How does one go about doing this?

Thanks in advance.

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


View Profile
« Reply #1 on: January 23, 2006, 09:09:43 am »

I'm constructing a tiny first-person-shooter and am trying to get the current weapon displayed on the screen such that it moves with the camera movement - ala half-life, doom, etc. How does one go about doing this?

Thanks in advance.



At this moment the only way is to do it manually in application code. i.e. manually move the weapon mesh to the location of the camera whenever the camera moves.

Greetings,
Logged
phototrix
Newbie
*
Posts: 20


View Profile
« Reply #2 on: January 24, 2006, 04:37:13 pm »

Ok, I got that working. The issue is that the weapon keeps getting clipped off with a little bit of camera movement. E.g, after rotating right the weapon gets clipped off and re-appears when I rotate left. Same this happens when rotating left and moving forward. The weapon remains in view when the camera is moved backwards.
The center-point of the weapon is set to the center-point of the camera.
What could be causing this? Here is the relevant code:

void Test::ProcessFrame()
{
  csTicks elapsedTime = vc->GetElapsedTicks();
  float speed = (elapsedTime / 1000.0f);

  iCamera* camera = view->GetCamera();
  iMovable* movable = weapon->GetMovable();

  if (kbd->GetKeyState(CSKEY_RIGHT)) {
    camera->GetTransform().RotateThis(CS_VEC_ROT_RIGHT, speed);
    movable->GetTransform().RotateThis(CS_VEC_ROT_RIGHT, speed);
  }
  if (kbd->GetKeyState(CSKEY_LEFT)) {
    camera->GetTransform().RotateThis(CS_VEC_ROT_LEFT, speed);
    movable->GetTransform().RotateThis(CS_VEC_ROT_LEFT, speed);
  }
  if (kbd->GetKeyState(CSKEY_PGUP)) {
    camera->GetTransform().RotateThis(CS_VEC_TILT_UP, speed);
    movable->GetTransform().RotateThis(CS_VEC_TILT_UP, speed);
  }
  if (kbd->GetKeyState(CSKEY_PGDN)) {
    camera->GetTransform().RotateThis(CS_VEC_TILT_DOWN, speed);
    movable->GetTransform().RotateThis(CS_VEC_TILT_DOWN, speed);
  }
  if (kbd->GetKeyState(CSKEY_UP)) {
    camera->Move(CS_VEC_FORWARD * 4 * speed);
  }
  if (kbd->GetKeyState(CSKEY_DOWN)) {
    camera->Move(CS_VEC_BACKWARD * 4 * speed);
  }

  // position the weapon relative to the camera position
  movable->SetPosition(camera->GetTransform().GetO2TTranslation());

  if (!g3d->BeginDraw(engine->GetBeginDrawFlags() | CSDRAW_3DGRAPHICS))
    return;

  view->Draw();
}
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #3 on: January 24, 2006, 05:14:43 pm »

As the api documentation of iMovable states you MUST do UpdateMove() after moving or rotating a mesh. This is causing your clipping problems.

Greetings,
Logged
phototrix
Newbie
*
Posts: 20


View Profile
« Reply #4 on: January 24, 2006, 05:20:08 pm »

Oops! Thanks!! It is working now Smiley
Logged
Photonman
Newbie
*
Posts: 8


View Profile Email
« Reply #5 on: May 17, 2006, 07:30:03 pm »

Oops! Thanks!! It is working now Smiley
Hmm interesting code, but this is simple. What any solving this problem? For example parent camera to sprite: sprite follow the camera automatic. I think this is sprite socket in CS, but I don't know it is good way on this problem...
http://www.crystalspace3d.org/tikiwiki/tiki-index.php?page=Using+Sprite+Sockets&highlight=sprite
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.714 seconds with 17 queries.