Jump to content

Onclick event


Elmar
 Share

Recommended Posts

I want to write the program as follow:

To create virtual walk on the scene. (It's i can) and to create onclick event on the meshes in the same scene. I want that there are done some works when i click on the mesh.

 

What can you advice me?

 

P.S. When i did visualization before there didn't display mouse.

Link to comment
Share on other sites

I am working on this for my own GUI manager and other stuff, what I'm doing is initializing a key/value pair array (key=specific mesh ID, value=click callback), then calling CameraPick and finally calling the callback matching the picked entity mesh ID on the array.

 

I don't know what should be the correct C++ code for this, since I work on C#.

?? FRANCESCO CROCETTI ??

http://skaredcreations.com

Link to comment
Share on other sites

You can do something like this:

 

Mouse mymouse;
Camera mycam;
Pick mypick;
Entity myent;

mycam.Create();

if(mymouse.IsDown())
{
       if(mycam.GetPick(mypick,Vec3(mymouse.GetX(),mymouse.GetY(),1000)))
{
              //Do something when the mesh GetPicked
              myent = mypick.entity;
              myent.SetColor(Vec4(1,0,0,0));
       }
}

Link to comment
Share on other sites

You can do something like this:

 

Mouse mymouse;
Camera mycam;
Pick mypick;
Entity myent;

mycam.Create();

if(mymouse.IsDown())
{
       if(mycam.GetPick(mypick,Vec3(mymouse.GetX(),mymouse.GetY(),1000)))
{
              //Do something when the mesh GetPicked
              myent = mypick.entity;
              myent.SetColor(Vec4(1,0,0,0));
       }
}

 

There are occuries error. GetPick and Setcolor functions are not found. What is the problem?

Link to comment
Share on other sites

TCamera mycam = CreateCamera();
TPick mypick;
TEntity myent;

if (MouseDown())
{
       if (CameraPick(mypick, mycam, Vec3(MouseX(),MouseY(),1000)))
       {
              //Do something when the mesh GetPicked
              myent = mypick.entity;
              EntityColor(myent, Vec4(1,0,0,0));
       }
}

 

To know what entity has been picked you can check a key previously stored with GetEntityKey(). I would filter the CameraPick for a specific CollisionType which you need (you can also specify a pickfilter callback for more advanced filtering).

?? FRANCESCO CROCETTI ??

http://skaredcreations.com

Link to comment
Share on other sites

How i can do so that, mouse is display? I create controller without displaying mouse..

 

Controller isn't a input manager, a controller is an Entity. You doesn't need to create a mouse in C/engine.h just use the mouse functions. The mouse that the engine uses is the Windows default mouse, but if you want a custom icon you can draw a image at the same position as the mouse and hide the windows mouse(HideMouse() using engine.h).

 

Sorry about my english.

Link to comment
Share on other sites

Now my problem is connected with functions. Which functions can i use for selecting model and creating onclick select?

 

TCamera mycam = CreateCamera();
TPick mypick;
TEntity myent;

if (MouseDown(1))
{
       if (CameraPick(&mypick, mycam, Vec3(MouseX(),MouseY(),1000)))
       {
              //Do something when the mesh GetPicked
              EntityColor(mypick.entity, Vec4(1,0,0,0));
       }
}

 

To know what entity has been picked you can check a key previously stored with GetEntityKey(). I would filter the CameraPick for a specific CollisionType which you need (you can also specify a pickfilter callback for more advanced filtering).

 

But like ZioRed said you need to identify your mesh/model with GetEntityKey()(or myent.GetKey() in LEO) or your entire scene will be selectable, in other words if you have 2 diferent models in the same scene they will be the same (like a Wall and a Soldier). You can set the EntityKey youself if you want.

Link to comment
Share on other sites

In my game I have an array of characters which have a slot number and a mesh in its properties, so in the selection screen I initialize the characters meshes and set the relative slot number (SetEntitiKey(characterMesh, "slot", slot_number)), so after the pick call I check the "slot" key of the entity to know what character has been clicked (I set mouse visible for that).

?? FRANCESCO CROCETTI ??

http://skaredcreations.com

Link to comment
Share on other sites

I don't know what you are doing or what you want to do, I only explained a scenario sample of handling click on a mesh ;)

 

There's no difference about adding the models at runtime or in the editor. If you add them in the editor then you can check "name" with GetEntityKey since you should know what are the names or however you can use LUA scripting for your clickable models in which are set a custom property which you will check against with GetEntityKey.

?? FRANCESCO CROCETTI ??

http://skaredcreations.com

Link to comment
Share on other sites

Elmar,

 

1) Make a scene in the editor with just some terrain and a few oilbarrels in it.

2) Make a program from scratch that loads your scene correctly.

3) Add some movement via a character controller.

4) Use the code that Ziored proposed, and place it in the main loop.

5) Every time you are near an object and you click on it, it turns red.

Link to comment
Share on other sites

Elmar,

 

1) Make a scene in the editor with just some terrain and a few oilbarrels in it.

2) Make a program from scratch that loads your scene correctly.

3) Add some movement via a character controller.

4) Use the code that Ziored proposed, and place it in the main loop.

5) Every time you are near an object and you click on it, it turns red.

 

Thanks a lot. I did as you say.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...