Selecting invisible object
3 posters
Selecting invisible object
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
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
Re: Selecting invisible object
Check tutorial06_1 for more info on picking and tutorial14 for how to toggle objects visible/invisible during your "picking" pass.
Have fun!
Cheers,
Have fun!
Cheers,
Re: Selecting invisible object
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.
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
Re: Selecting invisible object
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...
Hope this helps,
Cheers,
ps: Pay attention to the comments in the tutorials, every details is important...
Re: Selecting invisible object
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!
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
Re: Selecting invisible object
My rendering code looks like this:
Objects not blinking, but SIO2_OBJECT_GHOST not working.
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
Re: Selecting invisible object
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 );
Re: Selecting invisible object
Finally i call glClear() both, before and after sio2ResourceSelect3D() and it works fine now.
But thanks for answer. It explains me a lot.
But thanks for answer. It explains me a lot.
jojky- Posts : 10
Join date : 2009-01-28
Re: Selecting invisible object
Hi ROm,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 );
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
Re: Selecting invisible object
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...
Re: Selecting invisible object
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
Re: Selecting invisible object
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.
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.
Re: Selecting invisible object
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)....
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
Re: Selecting invisible object
Here's a little function that I use to debug Bullet rays etc...
Not really fancy but quite useful...
- 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...
Re: Selecting invisible object
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...
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
Re: Selecting invisible object
Just use my little function above, you'll see it right away where your ray in 3d space is casted...
Re: Selecting invisible object
Hi, I have another stupid question related to previous one .
Is it possible to get size and location of object on screen?
Thanks
Is it possible to get size and location of object on screen?
Thanks
jojky- Posts : 10
Join date : 2009-01-28
Re: Selecting invisible object
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
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
Re: Selecting invisible object
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
Similar topics
» Tutorial 06 - Selecting an Object
» Transparency < 50% = Invisible. Why?
» Physic objects - ghost, invisible...
» physics object inside another physics object
» Get the 2D location of an 3D object
» Transparency < 50% = Invisible. Why?
» Physic objects - ghost, invisible...
» physics object inside another physics object
» Get the 2D location of an 3D object
Permissions in this forum:
You cannot reply to topics in this forum