ShiVa Developer Forum • View topic - selecting object in other user scene in hud(rendermap)
 

selecting object in other user scene in hud(rendermap)

All about the StoneScript

selecting object in other user scene in hud(rendermap)

Postby 25kb » 2018-09-28 06:30

okay so im not sure if this is already solved if its is i would appreciate it if you can link me there.

so i have this hud smaller than the screen. it is a render map and its source is in another scene of another user. now i want to click inside the HUD and whatever is hit in the other user scene will be selected.. i know handler on mouse button and scene.getfirstcollided etc. i think i need to scale something here. how do i achieve this? the paint demo uses pixelmap i guess so im stuck here.
Image
25kb
Fresh Boarder
Fresh Boarder
 
Posts: 7
Joined: 2017-11-28 08:58

Re: selecting object in other user scene in hud(rendermap)

Postby Badger » 2018-09-28 14:07

You need to look up the docs on camera.projectpoint and .unprojectpoint

Code: Select all
--i have two objects in scene. zbase is the reference object for depth on the z axis
--ztest follows the mouse based on the z position of zbase object
if (ztest and zbase) then
       
   local tx,ty,tz = 0,0,0
   local x, y, z = 0,0,0   

   --get tz to use for reference depth
   tx,ty,tz = camera.projectPoint ( hCam, object.getTranslation ( zbase, object.kGlobalSpace ) )

   --using that depth and the mouse x/y - nPointX, nPointY comes from the mouse handler
   x, y, z = camera.unprojectPoint ( hCam, nPointX, nPointY, tz)   

   --set the position of the ztest object (now it's on the mouse)
   object.setTranslation ( ztest, x, y, z, object.kGlobalSpace )

   --will use the camera translation in the raycast later
   local cx,cy,cz = object.getTranslation ( hCam, object.kGlobalSpace )

   --get translation of the test object (mouse x/y + depth of zbase as set before)
   local zx,zy,zz = object.getTranslation ( ztest, object.kGlobalSpace )

   --get direction and normalise
   local dx,dy,dz = math.vectorSubtract ( zx,zy,zz, cx,cy,cz )
   dx,dy,dz = math.vectorNormalize ( dx,dy,dz )

   --raycast from camera in direction at length 100 to hit sensor range 250/251
   local hHit, nDist, nID = scene.getFirstHitSensorWithIDInRange ( s, cx,cy,cz, dx,dy,dz, 100, 250,251 )
end if


In your case you'll need to convert your mouse position from the screen to x/y coords on your rendermap element and of course use the camera object in the second scene.
________________________________
˙ןǝnuɐɯɯǝ osןɐ ɯ,ı
User avatar
Badger
Gold Boarder
Gold Boarder
 
Posts: 198
Joined: 2012-05-11 08:42
Location: Australia

Re: selecting object in other user scene in hud(rendermap)

Postby 25kb » 2018-09-30 13:14

thanks badger. i did come up with a solution but yours is less messy and much better..
25kb
Fresh Boarder
Fresh Boarder
 
Posts: 7
Joined: 2017-11-28 08:58


Return to Game programming

Who is online

Users browsing this forum: No registered users and 4 guests

cron