About Store Forum Documentation Contact



Post Reply 
Dynamically change item coords
Author Message
AndrewBGS Offline
Member

Post: #1
Dynamically change item coords
I need this for equipping armour. What I did so far was just like the tutorials, fix the armour at some height that would perfectly fit on the character. However, for some other reasons, I need every item to have it's bottom of the mesh at height 0.

How can I add some height to the item only when I want to equip it on my character?

Or else, if I keep the item at non-zero height, can I get it's mesh's bottom position?
08-02-2013 08:53 AM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #2
RE: Dynamically change item coords
Is there a reason you can't have the mesh above 0?

If you really want to find the lowest point, you could create a lowestPoint variable and when the armor object is created, iterate through the mesh verts to find the very with the lowest Y. Set lowestPoint to Y, and you can use that to modify the height so the bottom or middle of the mesh is at 0.
The verts are something like myMesh->parts[j].base.vtx.pos(i), where i iterates the verts of mesh part j.
Untested example pseudo code:
Code:
for( int j = myMesh->parts.elms(  ); j > 0; --j; )
   REPA( myMesh->parts[j].base.vtx )
      if( myMesh->parts[j].base.vtx.pos( i ).y < lowestPoint )
         lowestPoint = myMesh->parts[j].base.vtx.pos( i ).y;
08-02-2013 01:42 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #3
RE: Dynamically change item coords
Ah, I see. I think it would work, but it looks unpleasant. I need it because when picking up items the player checks item.pos() which apparently is the (0,0,0) in item space. And if the item is at some 1-2 height (as the armour is for example), it is a little wrong. Especially since I use a Gothic way of picking items up, displaying their name when they're selected. Name is displayed at item.pos, which in armour's case is about 1 meter away from the armour.

Still a desirable solution would be to move the mesh before I equip it on the character. Can't I do that?
08-02-2013 02:30 PM
Find all posts by this user Quote this message in a reply
Pherael Offline
Member

Post: #4
RE: Dynamically change item coords
If I remember correctly mesh->box.down() should return mesh bottom position.

Quote:Still a desirable solution would be to move the mesh before I equip it on the character.
Maybe manipulating with mesh.box could do the trick for you, but I never do that myself, so not sure if it would work (idea only).
(This post was last modified: 08-02-2013 03:13 PM by Pherael.)
08-02-2013 03:12 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #5
RE: Dynamically change item coords
(08-02-2013 03:12 PM)Pherael Wrote:  If I remember correctly mesh->box.down() should return mesh bottom position.

Quote:Still a desirable solution would be to move the mesh before I equip it on the character.
Maybe manipulating with mesh.box could do the trick for you, but I never do that myself, so not sure if it would work (idea only).

Good call- I forgot about the bounding box. I don't think moving the box would work; it would move the bounding, but not the actual vertices.

Pretty much any way it can be done through code is going to be ugly. It's probably best to just move the meshes. I think it will be less time and trouble in the long run, unless you already have a couple hundred pieces of armor.
08-02-2013 03:22 PM
Find all posts by this user Quote this message in a reply
Pherael Offline
Member

Post: #6
RE: Dynamically change item coords
Rubeus Wrote:I don't think moving the box would work; it would move the bounding, but not the actual vertices.
You're right smile
08-02-2013 03:49 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #7
RE: Dynamically change item coords
Ok, that mesh box sounds reasonable, but how is that created/set in the first place?
I currently have a box that seems to be as big as my world.
08-05-2013 01:19 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #8
RE: Dynamically change item coords
So nothing seems to have worked; I can't get any closer to writing text on the item except item.pos(), which can be up to 1,5 away from the items and looks weird. And I couldn't find any way at all to move the mesh before I equip it on my character.

Any other ideas...? Or maybe tell me how to set that mesh box or something?
If any of you played Gothic, that's the loot system I try to make here:

you get close to an item, you can see it's name written on it (+the highlight) and you can grab it. So I need the place where I need to write the actual text (which in most cases is item.pos()- but sometimes, like in the chest item case, pos is quite far from the actual item). Can someone please help?
08-06-2013 02:56 PM
Find all posts by this user Quote this message in a reply
SamNainocard Offline
Member

Post: #9
RE: Dynamically change item coords
I never played Gothic, so I'm not sure what you're trying to achieve.

But what about item.matrix, item.actor.pos/matrix, item.mesh.box*item.matrx, item.actor.shape(false).pos.
(This post was last modified: 08-07-2013 06:07 AM by SamNainocard.)
08-07-2013 06:01 AM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #10
RE: Dynamically change item coords
Awesome, item.actor.shape(false).pos() seems to do the trick! smile
I just hope it's not too much of a waste to call that long chain twice every frame (once for detecting the item, once for displaying the text) but at least it works smile
08-07-2013 07:01 AM
Find all posts by this user Quote this message in a reply
Post Reply