Elmar Posted May 18, 2010 Share Posted May 18, 2010 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. Quote Link to comment Share on other sites More sharing options...
ZioRed Posted May 18, 2010 Share Posted May 18, 2010 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#. Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Elmar Posted May 18, 2010 Author Share Posted May 18, 2010 But how can i do this with C++? Who know? Quote Link to comment Share on other sites More sharing options...
DWORD Posted May 18, 2010 Share Posted May 18, 2010 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)); } } Quote Link to comment Share on other sites More sharing options...
Elmar Posted May 19, 2010 Author Share Posted May 19, 2010 How i can do so that, mouse is display? I create controller without displaying mouse.. Quote Link to comment Share on other sites More sharing options...
Elmar Posted May 19, 2010 Author Share Posted May 19, 2010 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? Quote Link to comment Share on other sites More sharing options...
ZioRed Posted May 19, 2010 Share Posted May 19, 2010 That is the code using LEO objects Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Elmar Posted May 19, 2010 Author Share Posted May 19, 2010 What are equivalent functions in the engine.h? Quote Link to comment Share on other sites More sharing options...
ZioRed Posted May 19, 2010 Share Posted May 19, 2010 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). Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
AggrorJorn Posted May 19, 2010 Share Posted May 19, 2010 With Lua you can do this: http://leadwerks.com/werkspace/index.php?/topic/1817-pick-an-object/page__p__16575entry16575 Quote Link to comment Share on other sites More sharing options...
DWORD Posted May 19, 2010 Share Posted May 19, 2010 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. Quote Link to comment Share on other sites More sharing options...
Elmar Posted May 19, 2010 Author Share Posted May 19, 2010 Now my problem is connected with functions. Which functions can i use for selecting model and creating onclick select? Quote Link to comment Share on other sites More sharing options...
DWORD Posted May 19, 2010 Share Posted May 19, 2010 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. Quote Link to comment Share on other sites More sharing options...
ZioRed Posted May 19, 2010 Share Posted May 19, 2010 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). Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Elmar Posted May 20, 2010 Author Share Posted May 20, 2010 I don't enter my models with code(I do load from .sbx file). I gather my models in the scene and I only display my scene with code. Is that possible to pick that meshs? If yes, how? Thanks Quote Link to comment Share on other sites More sharing options...
ZioRed Posted May 20, 2010 Share Posted May 20, 2010 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. Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
AggrorJorn Posted May 20, 2010 Share Posted May 20, 2010 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. Quote Link to comment Share on other sites More sharing options...
Elmar Posted May 20, 2010 Author Share Posted May 20, 2010 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.