About Store Forum Documentation Contact



Post Reply 
Is it possible to attach animatable object to another object's slot
Author Message
tipforeveryone Offline
Bronze Supporter

Post: #1
Is it possible to attach animatable object to another object's slot
I need my character model holding a rotating device on his hand, but as tutorial, I only make it hold a "static" device, not animated one, I have to chose between:

C OrientM *hand = character.skel.getSlot("mySlot");
Matrix matrix;
matrix.setPosDir(hand.pos, hand.perp, hand.dir);
device.mesh->draw(matrix);
//this only draw hold device mesh, but can not draw animated one

and:

device.mesh->draw(device.skel);
//"device" is an animatable object and has proper skel animation in virtual bool update();

Please, give me some clue to solve my problem, thanks smile
07-18-2020 09:18 AM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #2
RE: Is it possible to attach animatable object to another object's slot
kinda confused of what you mean by this,

here how this work,

you have a slot on your hand.

you get that slot matrix ( which is pos, perp and dir )
then you can draw what ever you want, from the class of your choice, with this matrix, that is just the position in the world of the slot.

hope that helps
07-18-2020 03:44 PM
Find all posts by this user Quote this message in a reply
tipforeveryone Offline
Bronze Supporter

Post: #3
RE: Is it possible to attach animatable object to another object's slot
Ah, let me explain more, maybe it is just my confusion.
I suppose this is how an animatable object works with selected animation

Code:
class MyDevice : Game.Animatable{
virtual void create(Object &obj){super.create(obj);}
virtual bool update(){
    skel.updateBegin().clear()
    .animate(UID(_selectedAnimation), Time.time())
    .updateMatrix(actor.matrix()).updateEnd();
    return true;
}
virtual UInt drawPrepare(){
    mesh->draw(skel); return 0;
    //AFAIK: This will draw mesh with skel animation
    //And everything works fine here
}
}

And this is how to draw a mesh by a slot's matrix

Code:
//outside all functions
    MyDevice device;

//somewhere in void Init()
    device.create(*ObjectPtr(UID(_deviceModel_));
    device.pos(Vec(0,1,0)); //reposition device actor

//somewhere in void Render() after case: RM_PREPARE
    device.drawPrepare(); //draw device with animation

    //Below I try to attach my animated device at myCharacter hand slot

    C OrientM *slot = myCharacter.skel.getSlot("hand");
    //NOTE: myCharacter is an animatable object too

    Matrix m; m.setPosDir(slot.pos, slot.perp, slot.dir);
    device.mesh->draw(m);
    //I expected that MyDevice object will be draw at the position of "hand" slot
    //Mimic the example code from "Items slot" tutorial
    //but it just won't work for my animated device

This is why I confused. I can't use mesh->draw() for both of 2 purposes, draw animation and draw position, right?

Please explain if you can, I feel myself so dumb :(
(This post was last modified: 07-18-2020 06:13 PM by tipforeveryone.)
07-18-2020 06:08 PM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #4
RE: Is it possible to attach animatable object to another object's slot
this should be enough for draw no ?
device.drawPrepare(); //draw device with animation

the rest should be done in update, and not draw.
device.mesh->draw(m); remove this

you dont need to call draw mesh again, all you need is to set the matrix of the obj to be "m" matrix
07-18-2020 06:54 PM
Find all posts by this user Quote this message in a reply
tipforeveryone Offline
Bronze Supporter

Post: #5
RE: Is it possible to attach animatable object to another object's slot
I tried using this in update() before:

device.matrix(slotMatrix); but it makes smooth movement, I don't want that because I need my device to be held in mycharacter hand slot

in "Items slot" example when using mesh->draw(matrix) I don't get smooth movement of attached object, check out the video below, I am testing for my gun

https://youtu.be/p5O3lZ1N6z8

How to fix
07-19-2020 06:26 AM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #6
RE: Is it possible to attach animatable object to another object's slot
not sure, normally you should have in that order:
-your character update, that will update the slots position. with set matrix and all the fun stuff.
-your gun update, which your obj will get the matrix of the slots. with set matrix and all the fun stuff as well.

totally separately the drawing of the meshes according to the skel ( no update there, as order can be important )
07-20-2020 12:43 AM
Find all posts by this user Quote this message in a reply
tipforeveryone Offline
Bronze Supporter

Post: #7
RE: Is it possible to attach animatable object to another object's slot
Thank you, order is really important! Problem solved!
07-20-2020 06:34 AM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #8
RE: Is it possible to attach animatable object to another object's slot
good to hear smile
07-20-2020 07:06 AM
Find all posts by this user Quote this message in a reply
Post Reply