About Store Forum Documentation Contact



Post Reply 
Draw item on boneless slot
Author Message
AndrewBGS Offline
Member

Post: #1
Draw item on boneless slot
I'm trying to put some apples in a tree. The tree doesn't have bones (maybe that's an issue?) but it does have slots;
So just like with characters and inventory, I have a container of items in my tree class where I add the apples, then I find some slots (just one fixed slot for testing), and try to place the apple there. By debugging, apparently the apple is created, placed on the slot, and is drawn on every frame. However, I can't see the apple (the slot is put in a very visible place levitating above the tree). The tree is visible however. Also, the apple seems to be created correctly; I can loot the tree and I get a "correct" apple. Any idea what I'm missing?

There's some code below in case it helps:


Code:
void create(Game.ObjParams &obj)
   {  
      super.create(obj);
      cskel.create(mesh->skeleton());
       if(Param *p=obj.findParam("showItems"))   showItems=p.asBool();
      
      for(Game.ObjParamsPtr op=&obj; op; op=op->base()) // iterate all bases
         FREPA(op->sub_objs)     // for and has i inside
            {
            Item &item=items.New();
            item.create(op->sub_objs[i]);
            item.actor.active(false);  
            }
    
     if(showItems)
      {
         for(int i = items.validElms() - 1;  i>=0;  i--)
            if(C OrientP *point=cskel.findPoint(8"slot1"))
              items[i].matrix(*point);            
      }    
   }
  
   uint drawPrepare()
   {  if(showItems)
             for(int i = items.validElms() - 1;  i>=0;  i--) items[i].drawPrepare();        
      return super.drawPrepare();  
   }
08-06-2013 03:01 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #2
RE: Draw item on boneless slot
Did you try making a breakpoint on your for loop to see if the draw is being called properly?
08-07-2013 08:59 PM
Find all posts by this user Quote this message in a reply
Rofar Offline
Member

Post: #3
RE: Draw item on boneless slot
Does the apple item mesh have a physics shape created for it?
08-07-2013 10:35 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #4
RE: Draw item on boneless slot
Yes, to both; I have a silly DebugWindow class, and as I said, the item is both created and the draw function is called; And as I mentioned the apple is fine, since it can be rendered fine by itself; so yes, it does have a physical body;

Could this have something to do with my object extending the Static class?
08-08-2013 06:43 AM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #5
RE: Draw item on boneless slot
Extending the static class just means you can't move your apples around. So unless you want them to grow legs....
Is it (supposedly) drawing where you expect it to?
I had a similar issue before; it was caused by my save/load functions not loading the settings that the object needed. Are you saving the apple params as needed?
08-08-2013 05:58 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #6
RE: Draw item on boneless slot
What exactly do you mean by drawing "where you expect it to"? Code-wise, or world-wise? If world, how can I find out where it draws it? (It did occur to me also that maybe the apples are drawn somewhere but I don't see them)

Why would save/load matter at first sight? They don't show after loading the world, I'm not concerned with loading yet. But anyway, I'm sure I save them right; independent apples behave completely as expected under all circumstances.
08-08-2013 06:02 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #7
RE: Draw item on boneless slot
Print out the location they are drawing. If you are getting 0,0,0 or some crazy number, you know you have a bug.
My issue with the objects not drawing was caused by not having a save/load. I also didn't have the world do an initial update before adding my objects, so it tried to immediately save every object the first frame, then load all objects for the second on. Calling world.update after creating the world was the real fix, but fixing the save/load let me see what was going on.
Now, if you have single apples that work, but you change the code to use multiple but it stops working, don't you think there's a bug in your code? (or using the multiple objects no longer works well enough with the default save/load function....)
08-08-2013 06:24 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #8
RE: Draw item on boneless slot
You may have misunderstood, nothing stopped working, everything acts fine, is just that I can't see those apples in the tree. I'll try with just one and print its position, that might give me some ideas. I'll handle to save/load also, but I doubt this is the problem in my case. but it needs to be done anyway. I'll see what I can find out.
08-08-2013 06:34 PM
Find all posts by this user Quote this message in a reply
kasinova Offline
Member

Post: #9
RE: Draw item on boneless slot
It might be easier to give the tree an ID and make an apple object separately, giving it a tree ID to identify with. That way you can draw the apple in lets say a random position within a sphere according to the tree's radius.
Just an idea I suppose!
08-09-2013 12:21 AM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #10
RE: Draw item on boneless slot
It's a good idea, and it might probably work. I'll talk with my friends and see if we prefer picking items independently or as if from a container; but anyway, for science's sake, I'd like to get this problem fixed grin
08-09-2013 06:54 AM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #11
RE: Draw item on boneless slot
So, getting back to my beloved coding problems.
I debugged my tree, and I was surprised to see the issue is somewhere here:

if(C OrientP *point=cskel.findPoint(8"slot1"))
{ //DebugWin.updateTxt(S+point.pos.x); -- 0!!! How can it be ?
items[i].matrix(*point);
}

As my brilliant comment shows, it turned out the position of the point finding my slot was (0, 0, 0). And I checked, the apple from the tree was indeed in the (0, 0, 0) of the world. So it all makes sense. Except for why the hell does that happen?

If it wouldn't find the slot, it shouldn't enter the IF. If it does... how can it be at (0, 0 , 0)? Does anyone have any idea?

I'm still thinking it's because my tree has no bones. The slot is found using cskel.
As my tree is a static object, it has no default cskel. So I made it manually in the create function:

cskel.create(mesh->skeleton()); -- found this somewhere in the tutorials I think

My guess would be the problem is somewhere here... but I couldn't say what's wrong. Maybe someone more experienced can enlighten me?
(This post was last modified: 08-24-2013 10:59 AM by AndrewBGS.)
08-24-2013 10:56 AM
Find all posts by this user Quote this message in a reply
SamNainocard Offline
Member

Post: #12
RE: Draw item on boneless slot
What about using skeleton instead of slot? by replacing those slot with bone, then mesh->skeleton()->findBone("").pos or something.
08-24-2013 01:23 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #13
RE: Draw item on boneless slot
Well, as the name of the post suggests, I have no bones. It's a tree. It doesn't need animations, so why would it have bones? Or skeleton? I just want some apples to appear in it at fixed positions. Slots seemed like a good idea; On characters I was able to use slot un-attached to bones with no problems.

So no, I can't use findBone because I don't have bones. And I think I would over-complicate things to make bones on static objects just so I can plant apples on them. It has to be another way.
08-24-2013 01:27 PM
Find all posts by this user Quote this message in a reply
SamNainocard Offline
Member

Post: #14
RE: Draw item on boneless slot
I'm thinking about using skeleton for apple position instead of bone slot, of course not a whole tree skeleton for animation, just a skeleton in place of bone slot instead, which used to attach apples on.
(This post was last modified: 08-24-2013 01:56 PM by SamNainocard.)
08-24-2013 01:50 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #15
RE: Draw item on boneless slot
Well, maybe it would work. Unfortunately, I know nothing about editing models (my experience is one month in Gmax. I made a boat that did absolutely nothing and was flat brown). So I have no idea how to do that.
Any chance I could add bones in esenthel?
And either way... there has to be another way grin Why the hell IS my point found and why are its coordinates (0,0,0) instead of the actual coordinates?
08-24-2013 02:00 PM
Find all posts by this user Quote this message in a reply
Post Reply