FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Selecting invisible object

3 posters

Go down

Selecting invisible object Empty Selecting invisible object

Post  jojky Fri Apr 24, 2009 2:08 am

I need increase hit region of an object and found some related topics:

https://sio2interactive.forumotion.net/sio2-engine-f3/increase-hit-region-of-an-object-t285.htm
https://sio2interactive.forumotion.net/blender-sio2-f2/can-t-make-transparent-objects-transparent-visible-t369.htm

but im not successfull.

Code snippet from second link looks easy, but can you explain it a little bit? Where and how i shoud use this code?

And second question: It is possible to exclude visible objects from selecting?

Thanks a lot

jojky

Posts : 10
Join date : 2009-01-28

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  sio2interactive Fri Apr 24, 2009 4:51 am

Check tutorial06_1 for more info on picking and tutorial14 for how to toggle objects visible/invisible during your "picking" pass.

Have fun!

Cheers,
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  jojky Fri Apr 24, 2009 5:55 am

Thanks very for you reply!

Did you mean this in tutorial14?

sio2EnableState(&my_object->flags, SIO2_OBJECT_GHOST);

I checked it out, object is invisible, it's alright, but its not possible to select them by taps.

jojky

Posts : 10
Join date : 2009-01-28

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  sio2interactive Fri Apr 24, 2009 6:15 am

Dude what sio2ResourceSelect3D is doing is just like sio2ResourceRender for solid & alpha object... so it means that all object that have a dst > 0.0f in the frustum and that are not ghost will be rendered... depending on what you want to do mess around with the object ghost or dst (as I show and explain in tutorial14) to toggle whatever you want to be picked then call Select3D... is that simple...

Hope this helps,

Cheers,

ps: Pay attention to the comments in the tutorials, every details is important...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  jojky Mon Apr 27, 2009 5:11 am

Thanks a lot, it works as you say!
My lazy brain finally got it.

But I have one problem yet.

If I call

glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT )

before

sio2ResourceSelect3D()

i can select objects which are not rendered, but at the moment when tap on display, this objects blinking.

Othervise, when i call glClear() after sio2ResourceSelect3D(), objects are not blinking, but cannot exclude them from selecting.

Where can be problem?

Thank you for any answer!

jojky

Posts : 10
Join date : 2009-01-28

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  jojky Mon Apr 27, 2009 5:21 am

My rendering code looks like this:

Objects not blinking, but SIO2_OBJECT_GHOST not working.

Code:

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

sio2WindowEnterLandscape3D();

sio2CameraSetPerspective( sio2->_SIO2camera, sio2->_SIO2window );

sio2CameraRender( sio2->_SIO2camera );

if( tap_select && sio2->_SIO2window->n_touch )
{
   glClear( GL_COLOR_BUFFER_BIT );
   
   sio2MaterialReset();
   
   for(int i = 0; i < 8; i++)
      sio2DisableState(&touchAreas[i]->flags, SIO2_OBJECT_GHOST);
   
   sio2EnableState(&gameArea->flags, SIO2_OBJECT_GHOST);
   
   tap_select = 0;
   
   t.x = sio2->_SIO2window->touch[ 0 ].y;
   t.y = sio2->_SIO2window->scl->y - sio2->_SIO2window->touch[ 0 ].x;
   
   selection = sio2ResourceSelect3D(sio2->_SIO2resource,
                            sio2->_SIO2camera,
                            sio2->_SIO2window,
                            &t );
   
   if(selection)
   {
      int racketNumber = getRacketNumber(selection);
      
      if(racketNumber >= 0)
         [currentMainGameView selectRacket:racketNumber];
      
      selection = NULL;
   }
   
   for(int i = 0; i < 8; i++)
      sio2EnableState(&touchAreas[i]->flags, SIO2_OBJECT_GHOST);
   
   sio2DisableState(&gameArea->flags, SIO2_OBJECT_GHOST);
}

glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );

ball->_SIO2transform->loc->x = x / GRAPHIC_RATIO + sub.x;
ball->_SIO2transform->loc->z = y / GRAPHIC_RATIO + sub.y;
sio2TransformBindMatrix( ball->_SIO2transform );

sio2CameraUpdateFrustum( sio2->_SIO2camera );

sio2ResourceCull( sio2->_SIO2resource, sio2->_SIO2camera );   

sio2ResourceRender(sio2->_SIO2resource, sio2->_SIO2window, sio2->_SIO2camera, SIO2_RENDER_SOLID_OBJECT | SIO2_RENDER_ALPHA_OBJECT );

sio2ObjectReset();

sio2MaterialReset();

sio2WindowLeaveLandscape3D();

jojky

Posts : 10
Join date : 2009-01-28

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  sio2interactive Mon Apr 27, 2009 5:30 am

What I would do is adjust to viewport ( sio2WindowUpdateViewport ) to be like 2x2 pixels around the hit spot, by having a smaller area to render the switch would be too fast for the eye to notice it... also make sure that your picking routine only pick once... not as long as the user touch the screen or something... if you are using physic you can simply cast a ray using sio2Unproject (to convert 2D points to 3D points ~ same as gluUnproject) to get the SIO2object handle doing something like this:


Code:

...
...
2D to 3D conversion to get the XY to XYZ coordinates
...
...
   btVector3 from( x, y, z ),
          to( x, y, z );

   btCollisionWorld::ClosestRayResultCallback ray_pick( from, to );

   sio2->_SIO2physic->_btSoftRigidDynamicsWorld->getCollisionWorld()-> ray_pick( p1, p2, ray_pick );

SIO2object *_SIO2object = ( SIO2object * )( ( btRigidBody * ) ray_pick.m_collisionObject )->getUserPointer();

printf("%s\n", _SIO2object->name );
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  jojky Mon Apr 27, 2009 6:01 am

Finally i call glClear() both, before and after sio2ResourceSelect3D() and it works fine now.
But thanks for answer. It explains me a lot.

jojky

Posts : 10
Join date : 2009-01-28

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  Francescu Mon Apr 27, 2009 4:36 pm

sio2interactive wrote:What I would do is adjust to viewport ( sio2WindowUpdateViewport ) to be like 2x2 pixels around the hit spot, by having a smaller area to render the switch would be too fast for the eye to notice it... also make sure that your picking routine only pick once... not as long as the user touch the screen or something... if you are using physic you can simply cast a ray using sio2Unproject (to convert 2D points to 3D points ~ same as gluUnproject) to get the SIO2object handle doing something like this:


Code:

...
...
2D to 3D conversion to get the XY to XYZ coordinates
...
...
   btVector3 from( x, y, z ),
          to( x, y, z );

   btCollisionWorld::ClosestRayResultCallback ray_pick( from, to );

   sio2->_SIO2physic->_btSoftRigidDynamicsWorld->getCollisionWorld()-> ray_pick( p1, p2, ray_pick );

SIO2object *_SIO2object = ( SIO2object * )( ( btRigidBody * ) ray_pick.m_collisionObject )->getUserPointer();

printf("%s\n", _SIO2object->name );
Hi ROm,

In your code example, 'p1 & p2' are 'from, to' 3D coordinates and are you computing p1 as a direction offset from p2 or as from the camera location + direction?

Thanks

Francescu

Posts : 136
Join date : 2009-03-18

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  sio2interactive Mon Apr 27, 2009 4:45 pm

No p1 is the point from in 3D that sio2Unproject then I give it an offset back (from) and an offset forward in the same direction (to), whatever collision object is in the middle of that line is the object that I pick...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  Francescu Mon Apr 27, 2009 5:11 pm

sio2interactive wrote:No p1 is the point from in 3D that sio2Unproject then I give it an offset back (from) and an offset forward in the same direction (to), whatever collision object is in the middle of that line is the object that I pick...

ok Thanks - how much of an offset would you give and do you only offset on 1 axis?

Francescu

Posts : 136
Join date : 2009-03-18

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  sio2interactive Mon Apr 27, 2009 5:15 pm

No all 3 based on you camera direction since you are obviously looking in that direction... It might cause some slight issues due to the perspective, but a bit of tweaking should do the trick.

In addition you can also check the Bullet SDK, they are using ray picking as well, and you can use the code above to get the SIO2object handle pretty easily.
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  Francescu Mon Apr 27, 2009 5:34 pm

Right - I did check the bullet SDK and tried their physic picking but it is not working that great for me - not sure why yet - What I have it working 90% of the time using SIO2Unproject() and some offset - but sometimes it just can't pick and I have to move my camera a bit (I have an orbit one btw)...I think my offset computation is not done right or optimum, that could explain why....

I could have used sio2ResourceSelect3D() but it needs to be in some GL context due to color picking right? since am doing picking outside of GL, am trying to go with a pure physic approach...

Interestingly enough the bullet picking function is quite complex and not as simple as I would have thought... ;-) (compared to some other physic picking methods posted on the SIO2 forums)....

Francescu

Posts : 136
Join date : 2009-03-18

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  sio2interactive Mon Apr 27, 2009 5:59 pm

Here's a little function that I use to debug Bullet rays etc...

Code:


void debug_points( btVector3 *_p1, btVector3 *_p2, float r, float g, float b )
{

   
      float tmp[ 6 ] = { _p1->x(), _p1->y(), _p1->z(),
              _p2->x(), _p2->y(), _p2->z() };

      glPushMatrix();
      {
         sio2ObjectReset();
         sio2MaterialReset();
         sio2WidgetReset();
         
         glColor4f( r, g, b, 1.0f );
         
         glVertexPointer( 3,
                      GL_FLOAT,
                      0,
                      &tmp );
         
         glPointSize( 5.0f );
         glDrawArrays( GL_POINTS, 0, 2 );
         glDrawArrays( GL_LINES, 0, 2 );
      }
      glPopMatrix();
      
}



Not really fancy but quite useful...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  Francescu Mon Apr 27, 2009 6:17 pm

Awesome. Thanks ROm...

My objects are fairly small so that's probably also why I need tweaking on the 'from, to' backward and forward offset computations as I do miss at times when my camera orbits in 3D space....I could also be wrong in computing those offsets though...

Francescu

Posts : 136
Join date : 2009-03-18

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  sio2interactive Mon Apr 27, 2009 6:40 pm

Just use my little function above, you'll see it right away where your ray in 3d space is casted...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  jojky Thu Apr 30, 2009 12:38 am

Hi, I have another stupid question related to previous one Smile.

Is it possible to get size and location of object on screen?

Thanks

jojky

Posts : 10
Join date : 2009-01-28

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  Francescu Thu Apr 30, 2009 9:28 am

You can get the radius of an SIO2object as:
float objRadius = _SIO2objectPtr->rad;

Object location:
vec2 objLoc = _SIO2objectPtr->_SIO2transform->loc;

Object size:
vec3 objSize = _SIO2objectPtr->_SIO2transform->scl;

Hope this helps

--Frank

Francescu

Posts : 136
Join date : 2009-03-18

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  jojky Wed May 06, 2009 6:52 am

Thank you, but what you wrote is location and rotation of object in 3D space. I want location on screen, where are 3D objects projected.

jojky

Posts : 10
Join date : 2009-01-28

Back to top Go down

Selecting invisible object Empty Re: Selecting invisible object

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum