Crystal Space
Welcome, Guest. Please login or register.
October 02, 2014, 11:29:42 am

Login with username, password and session length
Search:     Advanced search
9020 Posts in 2053 Topics by 8579 Members
Latest Member: Pawdykn
* Home Help Search Login Register
+  Crystal Space
|-+  Associate Projects
| |-+  CEL Discussion
| | |-+  Sticking to position
« previous next »
Pages: [1] 2 Print
Author Topic: Sticking to position  (Read 8122 times)
muffinpeddler
Full Member
***
Posts: 122


View Profile Email
« on: September 19, 2005, 05:23:18 am »

How can I recieve the position/rotation vector of my iPcMesh or iPcDefaultCamera and use that to stick a gun up front like in a first-person shooter?  I can lock it to the position vector, and it moves with my object, but it doesn't move exactly with it (it slides quickly then slows into the center), and it doesn't rotate any direction.  What would the best way to do this be?

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


View Profile
« Reply #1 on: September 19, 2005, 05:27:17 am »

How can I recieve the position/rotation vector of my iPcMesh or iPcDefaultCamera and use that to stick a gun up front like in a first-person shooter?  I can lock it to the position vector, and it moves with my object, but it doesn't move exactly with it (it slides quickly then slows into the center), and it doesn't rotate any direction.  What would the best way to do this be?

Thanks.

The best way is to use the socket system. Both spr3d and sprcal3d support this. The idea is that you define a triangle on the mesh where you can attach another model. If you are using the latest pseudo-stable or CVS you can find information about this in the manual.

Greetings,
Logged
muffinpeddler
Full Member
***
Posts: 122


View Profile Email
« Reply #2 on: September 19, 2005, 01:07:23 pm »

Thank you jorrit, I will look into that.
Logged
muffinpeddler
Full Member
***
Posts: 122


View Profile Email
« Reply #3 on: October 22, 2005, 07:07:46 pm »

Well, after having messed around with this, I am getting closer but still not there.  I am not using sockets, but I want to keep a iPcMesh object infront of my mesh with the same transformations of the mesh.  How can I get the transformations exactly from the mesh (rotation, position, etc.) and apply them to the weapon mesh?  I know how to do the transformations, but I am not sure which transformation functions to use and how to get the mesh's rotation and position.

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


View Profile
« Reply #4 on: October 22, 2005, 07:24:34 pm »

Well, after having messed around with this, I am getting closer but still not there.  I am not using sockets, but I want to keep a iPcMesh object infront of my mesh with the same transformations of the mesh.  How can I get the transformations exactly from the mesh (rotation, position, etc.) and apply them to the weapon mesh?  I know how to do the transformations, but I am not sure which transformation functions to use and how to get the mesh's rotation and position.

Thanks.

Instead of sockets you can also make the weapon a child of the parent. Just do parentMesh->GetChildren()->Add (weaponMesh). Then you can specify the transformation of the weapon relative to the parent. i.e. movable->SetTransform() will be relative.

Greetings,
Logged
muffinpeddler
Full Member
***
Posts: 122


View Profile Email
« Reply #5 on: November 06, 2005, 12:36:24 am »

Jorrit, I am still having some very bad problems with this.

I did the parent thing and the rotations are getting a little better.  So far, I can have the object rotate and point  in the same horizontal direction as my object and stick to its position, but I still cannot get any real camera view transformations, and this is with third person view and my game is first person.  Basically, I want to have my object look in the same direction as my camera and actor when in first person mode, and I want to be able to rotate the weapon around the actor.  I am considering not using a weapon and just shooting out objects, but even then, I can't make the objects shoot in the direction the camera and actor are looking (I say camera and actor because from what I know, the pccamera allows pitch movement, but the actor takes over the yaw?).  I am also a little confused about the 'this', 'other' and 'relative' transformations. 

Do you have any suggestions?  Thank you so much. 
Logged
genjix
Jr. Member
**
Posts: 53


View Profile
« Reply #6 on: November 11, 2005, 01:55:39 pm »

I know this is an ugly tack on, but maybe you could define a pctimer for the weapon and update it's position relative to the parent periodically.
Maybe you could also use iJoint (although I haven't had luck with this yet).
Logged
muffinpeddler
Full Member
***
Posts: 122


View Profile Email
« Reply #7 on: November 11, 2005, 11:46:20 pm »

Thanks for the reply.  Actually, I am having no problem keeping the weapon at the same position as the object as the title of this post might suggest.  The problem is rotating with the camera and the actor move and whatever is taking control of the rotation of the object in first person mode.  Basically, I am going for the first person view, with the gun stuck in the middle of the view
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #8 on: November 12, 2005, 07:31:09 am »

Thanks for the reply.  Actually, I am having no problem keeping the weapon at the same position as the object as the title of this post might suggest.  The problem is rotating with the camera and the actor move and whatever is taking control of the rotation of the object in first person mode.  Basically, I am going for the first person view, with the gun stuck in the middle of the view

Why not just take the transform of the camera and then set that transform to the object? That should put the object at exactly same location and orientation as the camera.

Greetings,
Logged
muffinpeddler
Full Member
***
Posts: 122


View Profile Email
« Reply #9 on: November 13, 2005, 04:49:42 am »

Thanks.  This is what I have so far, and it doesn't seem to be working well:
First, I add the weapon mesh as a child of the parent:
Code:
sourceMesh->GetMesh()->GetChildren()->Add(pcmesh->GetMesh());
And to update the position of the object:
Code:
        cameraTrans = pccamera->GetCamera()->GetTransform();
        iMovable *m = pcmesh->GetMesh()->GetMovable();
        m->Transform(cameraTrans.GetT2O());
        m->UpdateMove();
which seems to do nothing, so I add:
Code:
pclin->SetFullPosition(cameraTrans.This2OtherRelative(csVector3(0.0f, 2.0f, -2.0f)), PI, sourceMesh->GetMesh()->GetMovable()->GetSectors()->Get(0));
and it rotates around way too quickly and doesn't stick with the camera...Maybe I am confused with all this "Other" space stuff, but I am really stumped.  This is kind of killing my project.  Any suggestions?  Thanks.
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #10 on: November 13, 2005, 11:20:20 am »

Thanks.  This is what I have so far, and it doesn't seem to be working well:
First, I add the weapon mesh as a child of the parent:
Code:
sourceMesh->GetMesh()->GetChildren()->Add(pcmesh->GetMesh());
And to update the position of the object:
Code:
        cameraTrans = pccamera->GetCamera()->GetTransform();
        iMovable *m = pcmesh->GetMesh()->GetMovable();
        m->Transform(cameraTrans.GetT2O());
        m->UpdateMove();
which seems to do nothing, so I add:
Code:
pclin->SetFullPosition(cameraTrans.This2OtherRelative(csVector3(0.0f, 2.0f, -2.0f)), PI, sourceMesh->GetMesh()->GetMovable()->GetSectors()->Get(0));
and it rotates around way too quickly and doesn't stick with the camera...Maybe I am confused with all this "Other" space stuff, but I am really stumped.  This is kind of killing my project.  Any suggestions?  Thanks.


Hmm... I'm getting a bit confused by what exactly is wanted here. Could you perhaps try to clarify exactly what behaviour you want to have?

Greetings,
Logged
muffinpeddler
Full Member
***
Posts: 122


View Profile Email
« Reply #11 on: November 13, 2005, 06:31:06 pm »

What I am trying to do is first, as you suggested, make the weapon mesh a child of the parent, so all transforms will be relative.  Then, get the transform of the camera and apply it to the child mesh (to attempt to get yaw and pitch).  However, this doesn't seem to keep the object with the parent, so I added the linearmovement->SetFullPosition to set the position of the object relative to the parent.  That keeps the object with the parent, and the weapon rotates around (I offset the vectors to stick it infront of the parent) the parent) but it does not angle up or down and it spins around way too quickly so I only see the child in a few positions and rotations of the parent.  Am I not doing this right?  Thanks. 
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #12 on: November 13, 2005, 06:39:28 pm »

What I am trying to do is first, as you suggested, make the weapon mesh a child of the parent, so all transforms will be relative.  Then, get the transform of the camera and apply it to the child mesh (to attempt to get yaw and pitch).

I don't understand this. What exactly are you trying to achieve with that child mesh?

Greetings,
Logged
muffinpeddler
Full Member
***
Posts: 122


View Profile Email
« Reply #13 on: November 13, 2005, 07:08:54 pm »

Okay, think of a first person shooter game, like half-life, where the gun is positioned in the corner of the screen and stays there.  I want to achieve that.  Am I going about it the wrong way?  Could I do it orthagonally and keep the position 2d?  Basically, I am confused with all this and am trying to find ways that seem like they work. 

Thanks.
Logged
Bryan Krause
Guest


Email
« Reply #14 on: November 13, 2005, 10:52:22 pm »

Generally, in a first-person shooter game, weapons are built into the character model. When you see your own gun, however, you aren't actually seeing your weapon as other players are seeing it, but actually this is a 2D sprite. When walking you can play some tricks with the coords to mimic a "walking" motion. For playability, movement of the weapon never actually affects where the target is placed, usually this is simply represented by a cone of varying radius based on whether you are still/moving, standing/crouching, etc.

What I am trying to say is, I don't think you should be trying to draw the weapon for the player as a 3D mesh within the game, but rather draw it as a 2D sprite as part of the HUD.
Logged
Pages: [1] 2 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 9.445 seconds with 16 queries.