About Store Forum Documentation Contact



Post Reply 
SetHighlight() for the meshpart
Author Message
AlricDoRei Offline
Member

Post: #1
SetHighlight() for the meshpart
Hello.

Is there any way how to make SetHighlight() working with some part of the mesh?
My goal is to do something like this:
1. I have a 3d chracter(player). This character consists of 5 parts.
I have mouse cursor. When 1 of 5 parts is under mouse cursor it must be Highlighted. I am clicking on this mesh part and it disappears:(mesh->hide("name")).
I am trying to get it working during last days, but problem is:
(From the inventory tutorial)
Code:
UInt Item::drawPrepare()
{
   if(Lit==this)
       SetHighlight(Color(156,48,48,0));
...
Here is obj pointer == obj pointer. I tied to use MeshPart class. I can only change materials, etc. But I can't find how to:
1. Check mesh part is under mouse cursor or not.
2. And then, make highlignting for this part.
(This post was last modified: 07-06-2012 06:10 PM by AlricDoRei.)
07-06-2012 06:09 PM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #2
RE: SetHighlight() for the meshpart
Not sure if this will work but you can first attain the object hit
then access the mesh.
then check for each parts and see if another physics ray manages to hit the parts box and then draw special parameters from that?
if(mesh->parts(part).GetBox(box))
mesh->parts(part).draw
(This post was last modified: 07-06-2012 08:54 PM by Zervox.)
07-06-2012 08:52 PM
Find all posts by this user Quote this message in a reply
AlricDoRei Offline
Member

Post: #3
RE: SetHighlight() for the meshpart
(07-06-2012 08:52 PM)Zervox Wrote:  Not sure if this will work but you can first attain the object hit
Main.cpp:
Code:
void GetWorldObjectUnderCursor()
{
    Lit=NULL;
    if(!Gui.ms() || Gui.ms()==Gui.desktop())
    {
        Vec     pos, dir; ScreenToPosDir(Ms.pos(), pos, dir);
        PhysHit phys_hit;

        if(Physics.ray(pos, dir*D.viewRange(), &phys_hit, ~IndexToFlag(0)))
        {
            Lit=phys_hit.obj;
        }
    }
}
(07-06-2012 08:52 PM)Zervox Wrote:  then access the mesh.
I can't get the mesh from the phys_hit.obj
I can get it only from player.

(07-06-2012 08:52 PM)Zervox Wrote:  then check for each parts and see if another physics ray manages to hit the parts box and then draw special parameters from that?
Code:
Physics.ray(pos, dir*D.viewRange(), &phys_hit, ~IndexToFlag(0))
What is this flag/index actually do?
Code:
~IndexToFlag(0)
If I use:
Code:
~IndexToFlag(AG_CONTROLLER)
It selects only items(OBJ_ITEM). How I can get it working only for players and mesh part's box?

Here is my player function: (the whole Player highlighting)
Player.cpp:

Code:
UInt Player::drawPrepare()
{
     if(Lit==this)
     {
       SetHighlight(Color(48,48,48));

     }
     mesh->draw(cskel);
     SetHighlight(Color(0,0,0));
            
   return 0;
}
(This post was last modified: 07-07-2012 08:10 AM by AlricDoRei.)
07-07-2012 08:08 AM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #4
RE: SetHighlight() for the meshpart
Cast phys_hit obj to Player then.

it's supposed to be IndexToFlag(AG_CONTROLLER) from my experience to select only type actor group not ~IndexToFlag

if you do
~IndexToFlag(AG_CONTROLLER|AG_TERRAIN) excludes both terrain and controller
if you do
IndexToFlag(AG_CONTROLLER|AG_TERRAIN) it includes only controller and terrain
07-07-2012 01:38 PM
Find all posts by this user Quote this message in a reply
AlricDoRei Offline
Member

Post: #5
RE: SetHighlight() for the meshpart
(07-06-2012 08:52 PM)Zervox Wrote:  then check for each parts and see if another physics ray manages to hit the parts box and then draw special parameters from that?

How to check this?
I got mesh from phys_hit.obj and box from 1 of 5 mesh parts.

Main.cpp:
Code:
void GetWorldObjectUnderCursor()
{
   Lit=NULL;
      Vec     pos, dir;
      ScreenToPosDir(Ms.pos(), pos, dir);
      PhysHit phys_hit;
      if(Physics.ray(pos, dir*D.viewRange(), &phys_hit, IndexToFlag(AG_CONTROLLER)))
      {
          Lit=phys_hit.obj;
          
          Mesh *mesh = static_cast<Player*>(Lit)->mesh();
          Box box;
          if(mesh->parts(0).getBox(box))
          {
                                        
          }
      }
}
07-07-2012 04:07 PM
Find all posts by this user Quote this message in a reply
AlricDoRei Offline
Member

Post: #6
RE: SetHighlight() for the meshpart
Physics.ray doesn't work with parts boxes.

I tried to delete and hide mesh parts, but it doesn't have any effect.

Physics.ray(pos, dir*D.viewRange(), &phys_hit, IndexToFlag(AG_CONTROLLER)))
works even with deleted parts.
07-08-2012 12:55 PM
Find all posts by this user Quote this message in a reply
AlricDoRei Offline
Member

Post: #7
RE: SetHighlight() for the meshpart
(07-08-2012 12:55 PM)AlricDoRei Wrote:  Physics.ray doesn't work with parts boxes.

I tried to delete and hide mesh parts, but it doesn't have any effect.

Physics.ray(pos, dir*D.viewRange(), &phys_hit, IndexToFlag(AG_CONTROLLER)))
works even with deleted parts.

Found a problem.
Code:
mesh->box
method provides wrong data.
In the inventory demo tutorial
Item.cpp:

I am adding these lines:
Code:
UInt Item::drawPrepare()
{
    if(Lit==this)
    {
        SetHighlight(Color(48,48,48,0));
        this->mesh->box.draw(BLUE, true);//New line
    }
    
    UInt modes=super::drawPrepare();
    
    if(Lit==this)
    {
        SetHighlight();
        this->mesh->box.draw(BLUE, true);//New line
    }
    return modes;
}

Result:
http://i48.tinypic.com/xc19vb.png

If my mouse cursor is under this item(blue circle), I can see a box from the mesh of this item (red circle). Why is this box in the other part of the map?
Is this bug or not?
(This post was last modified: 07-09-2012 11:36 AM by AlricDoRei.)
07-09-2012 11:33 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #8
RE: SetHighlight() for the meshpart
try mesh->box * actor.matrix()

or OBox(mesh->box, actor.matrix());
07-09-2012 01:10 PM
Find all posts by this user Quote this message in a reply
AlricDoRei Offline
Member

Post: #9
RE: SetHighlight() for the meshpart
(07-09-2012 01:10 PM)Esenthel Wrote:  try mesh->box * actor.matrix()

or OBox(mesh->box, actor.matrix());

Thank you. Now it works.
07-09-2012 01:22 PM
Find all posts by this user Quote this message in a reply
AlricDoRei Offline
Member

Post: #10
RE: SetHighlight() for the meshpart
Is there any way how to check: if model part's box contains my point or not.
Modified inventory tutorial:
Here is my code:
Main.cpp:
Code:
void GetWorldObjectUnderCursor()
{
    Lit=NULL;
    partNumber = -1;
    if(!Gui.ms() || Gui.ms()==Gui.desktop())
    {
        Vec     pos, dir; ScreenToPosDir(Ms.pos(), pos, dir);
        PhysHit phys_hit;
        if(Physics.ray(pos, dir*D.viewRange(), &phys_hit, IndexToFlag(AG_CONTROLLER)))
        {
            Player *player = static_cast<Player*>(phys_hit.obj);
            for(int i = 0; i<player->mesh->parts.elms(); i++)
            {
                Box tempBox;
                player->mesh->parts(i).getBox(tempBox);

                OBox oo = OBox(tempBox, player->matrix());

                if(SweepPointBox(pos, dir*D.viewRange(), oo))
                {
                    partNumber = i;
                    Lit=phys_hit.obj;
                    break;
                }
            }    
        }
    }
}

Player.cpp:
Code:
UInt Player::drawPrepare()
{
    if(Lit==this)
    {
        Box bb;
        mesh->parts(partNumber).getBox(bb);
        OBox(bb, matrix()).draw(BLUE);
    }
    
         inv.drawPrepare();
         super::drawPrepare();

  return 0;
}

I tried many functions to check this, but it works only with SweepPointBox(...) and with one big problem.
Here it is:
http://i47.tinypic.com/v453km.png
Should to be: If my mouse cursor is under the head part, head box is drawing. If my mouse cursor is under the body part, body part is drawing.

With this problem:
It displays head box only if my mouse cursor is under the blue area(body - red area).
(This post was last modified: 07-09-2012 08:29 PM by AlricDoRei.)
07-09-2012 07:36 PM
Find all posts by this user Quote this message in a reply
Post Reply