MexSource Posted April 28, 2014 Share Posted April 28, 2014 Hey, I think something ins't functioning properly here. I have this: (In my player class) if (wd->KeyHit(Key::E)){ Vec2 mousepos = wd->GetMousePosition(); if (cam->Pick(mousepos.x, mousepos.y, pickinfo, 0.1)){ if (pickinfo.entity->GetKeyValue("tag") == "dbutton"){ //pickinfo.entity->SetKeyValue("tag", ""); System::Print("Entity picked, distance: " + String(pickinfo.distance)); pickinfo.entity->SetPosition(pickinfo.entity->GetPosition().x, pickinfo.entity->GetPosition().y - 2, pickinfo.entity->GetPosition().z); } } } But it only get triggered if i'm nearly directly in contact with that object. The line System::Print("Entity picked, distance: " + String(pickinfo.distance)); only says: Entity picked, distance -1 Is that -1 a convert problem or because I'm so close to the object that I'm touching it? Quote C++ :3 Link to comment Share on other sites More sharing options...
YouGroove Posted April 28, 2014 Share Posted April 28, 2014 Try with this Lua code example if self.entity.world:Pick(p0,p1, pickInfo, 0, true) then From Lua example : pickradius = 0.5 .... function App:Loop() ... if (self.camera:Pick(p.x,p.y,pickinfo,pickradius,true)) then self.picksphere:Show() self.picksphere:SetPosition(pickinfo.position) end Perhaps change your pickradius, and add "true" as last parameter. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
MexSource Posted April 28, 2014 Author Share Posted April 28, 2014 Perhaps change your pickradius, and add "true" as last parameter. I already did this sometimes Changing the pickradius to 0 doesn't work too Quote C++ :3 Link to comment Share on other sites More sharing options...
Haydenmango Posted April 29, 2014 Share Posted April 29, 2014 It seems your problem is that your two positions are your mousepos.x and mousepos.y. The two positions you need are 1 the area the pick starts from and 2 the area the pick will end. example positions that may work-- 1-self.entity:GetPosition() 2-target.entity:GetPosition() or 1-self.entity:GetPosition() 2-self.entity:GetPosition()+Vec3(0,0,5) Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding Link to comment Share on other sites More sharing options...
MexSource Posted April 29, 2014 Author Share Posted April 29, 2014 These variables are no Vec3, they are floats i think and look at the documentation Quote C++ :3 Link to comment Share on other sites More sharing options...
Haydenmango Posted April 29, 2014 Share Posted April 29, 2014 Did you even try it? and btw they are in Vec3. <p> "Syntax bool Pick(const Vec3& p0, const Vec3& p1, Pick& pick, float radius = 0.0, bool closest=false, bool recursive=false, int collisiontype=0) Parameters p0: the origin of the ray in global coordinates. p1: the terminal end of the ray in global coordinates." " PickInfo The pick class is a container for storing information about a pick operation. Members Vec3 position Vec3 normal Entity* entity Surface* surface Face* face int triangle" Using Vec3 positions for the start and end of the pick works for me. Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding Link to comment Share on other sites More sharing options...
AggrorJorn Posted April 29, 2014 Share Posted April 29, 2014 Mexsource is using a camera pick and not a global pick. He doesn't have to specify a starting 3d point as the campick takes the screencoordinates in to account as a startposition. http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/camera/camerapick-r199 @Mexsource, can you post a small demo a map and your code? you can also send a pm and I will have a look. Quote Link to comment Share on other sites More sharing options...
Haydenmango Posted April 29, 2014 Share Posted April 29, 2014 Ah I am very sorry then I was misinterpreting the issue. Disregard my info. Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding Link to comment Share on other sites More sharing options...
MexSource Posted April 29, 2014 Author Share Posted April 29, 2014 Ok here some more information: I try to create a game where you need to press a button, i wanted to do this with a raycast This is the pick code, it's from my MainPlayer.cpp "update" function that set up in my App::Loop function: if (wd->KeyHit(Key::E)){ Vec2 mousepos = wd->GetMousePosition(); if (cam->Pick(mousepos.x, mousepos.y, pickinfo, 0)){ if (pickinfo.entity->GetKeyValue("tag") == "dbutton"){ //pickinfo.entity->SetKeyValue("tag", ""); System::Print("Entity picked, distance: " + String(pickinfo.distance)); pickinfo.entity->Hide(); } } } on the map load i set the tag "dbutton" for every object that has "dbutton" in it's name. Later when I did the raycast i would remove the tag so the button is "pressed" (outcommented for testing). It should then print the distance from camera to object. And then the button should be set invisible, so you can see it's pressed. And here are my problems: The line that should output the distance only says -1 everytime and it only works if you are so close to the object, that you are nearly touching it. I will attach my current map. (Maybe it could help) Btw: maybe it's not working because my objects are csg objects? Is this enough explanation or do you need full code? Btw: why can't I upload .map files? map.zip Quote C++ :3 Link to comment Share on other sites More sharing options...
AggrorJorn Posted April 29, 2014 Share Posted April 29, 2014 That is the issue I think. When I try this with a model it works without problems. I have the map 25 error everyone else has, which doesn't allow me to test any further. Try attaching an empty lua file to the csg button. Quote Link to comment Share on other sites More sharing options...
MexSource Posted April 30, 2014 Author Share Posted April 30, 2014 I already attached a lua file, the csg box it's also detected with name. I will try to use a model when I'm back from on school Quote C++ :3 Link to comment Share on other sites More sharing options...
MexSource Posted April 30, 2014 Author Share Posted April 30, 2014 Not working, everything the same with the standart barrel included in the models folder Quote C++ :3 Link to comment Share on other sites More sharing options...
AggrorJorn Posted April 30, 2014 Share Posted April 30, 2014 Okay. I will be at home in a few hours and have a look. Quote Link to comment Share on other sites More sharing options...
MexSource Posted May 3, 2014 Author Share Posted May 3, 2014 Aggror is it working for you? If, could you please send me your map and the code you used? Quote C++ :3 Link to comment Share on other sites More sharing options...
Pastaspace Posted May 4, 2014 Share Posted May 4, 2014 I'm also getting this issue, performing a camerapick, then checking the pickinfo.distance variable, it's always -1 no matter what distance I'm at relative to the picked thing. Quote Link to comment Share on other sites More sharing options...
MexSource Posted May 4, 2014 Author Share Posted May 4, 2014 Are you using C++? Pastaspace Quote C++ :3 Link to comment Share on other sites More sharing options...
Rick Posted May 4, 2014 Share Posted May 4, 2014 Make a bug report with an example. In the meantime you can take the 2 points and find the distance via one of the helper functions to Vec3 I believe. Quote Link to comment Share on other sites More sharing options...
MexSource Posted May 4, 2014 Author Share Posted May 4, 2014 Yep, will do Here it is. Rick what do you mean, how could I do it? I tried: if (wd->KeyHit(Key::E)){ Vec3 pickPos2 = wd->GetMousePosition(); pickPos2.z = 10; if (wrd->Pick(cam->GetPosition(), cam->UnProject(pickPos2), pickinfo, 0.0F, true)){ if (pickinfo.entity->GetKeyValue("tag") == "dbutton"){ //pickinfo.entity->SetKeyValue("tag", ""); System::Print("Entity picked, distance: " + String(pickinfo.distance)); //pickinfo.entity->SetPosition(pickinfo.entity->GetPosition().x, pickinfo.entity->GetPosition().y - 2, pickinfo.entity->GetPosition().z); } } } wouldn't this do a raycast of length 10, in the looking direction of the camera? Because it only works when i look at a object in a certain angle that. Fixed it, you need to use: Vec3 pickPos2 = Vec3(contxt->GetWidth() / 2, contxt->GetHeight() / 2, 5); instead of Vec3 pickPos2 = wd->GetMousePosition(); pickPos2.z = 10; seems like mouseposition really returns the mouse position on whole screen not only for the window, how i thought Quote C++ :3 Link to comment Share on other sites More sharing options...
Pastaspace Posted May 7, 2014 Share Posted May 7, 2014 Are you using C++? Pastaspace Yep. No matter what distance my camera is from the pickinfo, it returns -1. 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.