Пример #1
0
	int Java_zte_irrlib_scene_Scene_nativeGetTouchedSceneNode(
		JNIEnv *env, jobject defaultObj, jint x, jint y, jint root)
	{
		ISceneNode* rootNode = smgr->getSceneNodeFromId(root);
		ICameraSceneNode* camera = smgr->getActiveCamera();
		if (!rootNode)
		{
			WARN_NODE_NOT_FOUND(root, GetTouchedSceneNode);
			return -1;
		}
		
		ISceneCollisionManager *collMgr = smgr->getSceneCollisionManager();
		core::line3d<f32> ray = collMgr->getRayFromScreenCoordinates(
            irr::core::position2di(x, y), camera); 
		core::vector3df intersection; 
		core::triangle3df hitTriangle;  
		scene::ISceneNode * selectedSceneNode =
		collMgr->getSceneNodeAndCollisionPointFromRay(
			ray,
			intersection,	//intersection position
			hitTriangle,	//hit triangle
			0,				//idBitMask: 0 to test all nodes
			rootNode		//root node to search from
		);
		if(selectedSceneNode) return selectedSceneNode->getID();
		else return 0;
	}
Пример #2
0
/*********************************************************************
 * Casts a ray to determine whether or not the soldier can see
 * the player for use with movement and shooting
 * Returns: a boolean value
 *********************************************************************/
bool Soldier::isPlayerVisible(){
    ray.end = sceneNode->getPosition();
	ray.start = gameInstance->getCamera()->getPosition();

	ISceneCollisionManager* collMan =
	    gameInstance->getSceneManager()->getSceneCollisionManager();
	vector3df intersection;
	triangle3df hitTriangle;

	ISceneNode * selected =
		collMan->getSceneNodeAndCollisionPointFromRay(
		ray, intersection, hitTriangle, IDFlag_IsPickable, 0);
    if (selected == sceneNode)//Direct line of sight
        return true;
    return false;	
}
Пример #3
0
 /// @param x screen x-coordinate for active camera
 /// @param y screen y-coordinate for active camera
 /// @return Approximate 3d position of the click
 Vector3f SimContext::GetClickedPosition(const int32_t& x, const int32_t& y)
 {
     Pos2i pos(x,y);
     ISceneCollisionManager* collider = mIrr.getSceneManager()->getSceneCollisionManager();
     // get ray
     Line3f ray = collider->getRayFromScreenCoordinates(pos);
     LOG_F_DEBUG("collision", "screen coordinates: " << pos << ", ray: " << ray.start << " - " << ray.end << ", length: " << ray.getLength());
     Vector3f collision_point;
     Triangle3f collision_triangle;
     ISceneNode* collision = collider->getSceneNodeAndCollisionPointFromRay(ray, collision_point, collision_triangle);
     if (collision) {
         SimEntityPtr ent = mpSimulation->FindBySceneObjectId(collision->getID());
         LOG_F_DEBUG("collision", "screen coordinates: " << pos << " colliding with: " << ent << " at: " << collision_point);
         return ConvertIrrlichtToNeroPosition(collision_point);
     } else {
         LOG_F_WARNING("collision", "screen coordinates: " << pos << " did not collide with any geometry!");
         return ConvertIrrlichtToNeroPosition(ray.end);
     }
 }
Пример #4
0
    /// @param hitEntity the entity intersected by the ray
    /// @param hitPos the position of the intersection
    /// @param origin origin of the ray to cast
    /// @param target target of the ray to cast
    /// @param type bitmask of the objects to care about or 0 for 'check all'
    /// @param vis show rays?
    /// @param foundColor the color to use if vis is true and an intersection is found
    /// @param noneColor the color to use if vis is true 
    /// @return first intersection info tuple(sim, hit) with SimEntityData sim and Vector3f hit (hit location) or ()
    /// Find the first object that intersects the specified ray
    bool SimContext::FindInRay( SimEntityData& hitEntity,
                                Vector3f& hitPos,
                                const Vector3f& origin, 
                                const Vector3f& target, 
                                const uint32_t& type, 
                                const bool vis, 
                                const SColor& foundColor,
                                const SColor& noneColor
                              )
	{
        ISceneCollisionManager* collider = mIrr.getSceneManager()->getSceneCollisionManager();
        Assert(collider);
        Line3f ray(ConvertNeroToIrrlichtPosition(origin), ConvertNeroToIrrlichtPosition(target));
        Triangle3f outTriangle;
        ISceneNode* node = collider->getSceneNodeAndCollisionPointFromRay
            (ray, hitPos, outTriangle, type);
        // convert back into our coord system
        hitPos = ConvertIrrlichtToNeroPosition(hitPos);
        if (node && node->getID() >= kFirstSimId)
        {
            // we found a sim node, so return its data
            SimEntityPtr ent = getSimulation()->FindBySceneObjectId(node->getID());
            if (ent)
            {
                // return the result: (sim, hit)
                hitEntity = ent->GetState();
                // draw a ray if requested
                if (vis)
                {
                    LineSet::instance().AddSegment(origin, hitPos, foundColor);
                }
                return true;
            }
        }
        if (vis)
        {
            LineSet::instance().AddSegment(origin, target, noneColor);
        }
        return false;
	}
Пример #5
0
// selectObject
// detect list objs at mouse xy	
void CDocument::selectObject( int mouseX, int mouseY, bool isControlHold )
{	
	ISceneManager *smgr = getIView()->getSceneMgr();	
	
	ICameraSceneNode *camera = smgr->getActiveCamera();

	// if no camera
	if (  camera == NULL )
		return;

	ISceneCollisionManager *collMan = smgr->getSceneCollisionManager();

	// get select ray
	core::line3df selectRay = getIView()->getSelectRay();
	
	// check hit test
	core::vector3df intersection;
	core::triangle3df hitTriangle;

	// check select
	ISceneNode *selectedSceneNode = collMan->getSceneNodeAndCollisionPointFromRay
		(
			selectRay,
			intersection,
			hitTriangle
		);
	
	if ( selectedSceneNode )
	{
		CGameObject *pObj =	searchObject( selectedSceneNode->getID() );
		
		// try find parent
		while ( pObj == NULL )
		{
			selectedSceneNode = selectedSceneNode->getParent();
			if ( selectedSceneNode == NULL )
				break;
			pObj = searchObject( selectedSceneNode->getID() );
		}

		// add to select list
		if ( pObj && pObj->isVisible() )
		{
			if ( isControlHold == false || pObj->getObjectState() == CGameObject::Normal )
				m_selectObjects.push_back( pObj );
			else
			{
				pObj->setObjectState( CGameObject::Normal );
				ArrayGameObjectIter i = m_selectObjects.begin(), iEnd = m_selectObjects.end();
				while ( i != iEnd )
				{
					if ( (*i) == pObj )
					{
						m_selectObjects.erase( i );
						break;
					}
					i++;
				}
			}
		}

	}

}