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; }
s32 Menu::coordinatesToIndex(s32 x, s32 y) { ISceneCollisionManager* collision = _game->getDevice( )->getSceneManager()->getSceneCollisionManager(); ISceneNode* node = collision->getSceneNodeFromScreenCoordinatesBB( vector2d<s32>(x, y), 0, false, _rootNode); return _buttons.linear_search(node); }
std::list<wpObject> const& Scene::pick (vec2 const& p, std::tr1::function<bool(vec2 const&, vec2 const&)> const& pred) { if( pred == 0 ) return pick(p); picked_temporary_.clear(); if( !allow_picking_ ) return picked_temporary_; ISceneCollisionManager* colm = getCollisionMgr(); BOOST_FOREACH(Node2ViewPair& nv, node2view_) { position2di pos = colm->getScreenCoordinatesFrom3DPosition(nv.first->getAbsolutePosition(), camera_); if( pred(p, vec2(pos.X, pos.Y)) ) picked_temporary_.push_back( nv.second ); }
/********************************************************************* * 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; }
/// @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); } }
/// @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; }
void SelectionSystem::update ( float timestep ) { EventReceiver::SMouseState mouseState = *EventReceiver::getMouseState(); // Calculate click point on terrain ISceneCollisionManager* colmgr = Game::game.getRendMgr()->getSceneManager()->getSceneCollisionManager(); line3df ray = colmgr->getRayFromScreenCoordinates(EventReceiver::getMouseState()->position); vector3df point; triangle3df triangle; ISceneNode* node; int hitID = -1; if ((hitID = colmgr->getSceneNodeFromRayBB(ray)->getID()) > -1) { //std::cout << "mouse over" << std::endl; } if (mouseState.leftPressed) { if (!dragging) { dragging = true; clickPos = vector2d<int>(mouseState.position.X, mouseState.position.Y); mousePos = vector2d<int>(mouseState.position.X, mouseState.position.Y); } else { mousePos = vector2d<int>(mouseState.position.X, mouseState.position.Y); } } else { if (dragging) { selectObjects(); dragging = false; int hitID = -1; if ((hitID = EventReceiver::getHoverObject()) > -1) { if (Game::game.getObjMgr()->getObjectComponent<SelectableComponent>(hitID, "SelectableComponent") != nullptr) { Game::game.getObjMgr()->getObjectComponent<SelectableComponent>(hitID, "SelectableComponent")->selected = true; } } } } }
void IdleBoard::Execute(BattleBoard* pField, u32 elapsedTime) { HandleEvent(pField, elapsedTime); // check if there are clicked card static EventReceiver* pEventReceiver = &(EventRcv); position2di posMouse; if (pEventReceiver->IsLeftMouseBtnDown(posMouse)) { pEventReceiver->SetLeftMouseBtnDown(false); ISceneCollisionManager* pCollisionManager = IrrDvc.GetSmgr()->getSceneCollisionManager(); ISceneNode* pSelectedCard = pCollisionManager->getSceneNodeFromScreenCoordinatesBB(posMouse); // send message Dispatcher->DispatchMsg(SEND_MSG_IMMEDIATELY, pField->ID(), pSelectedCard->getID(), MSG_CARD_CLICKED, null); } }
// 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++; } } } } }
int main(void){ MyEventReceiver receiver; //Device, driver et graphe de scene irr::IrrlichtDevice* device = irr::createDevice(irr::video::EDT_OPENGL, irr::core::dimension2d<irr::u32>(800, 600), 32, false, false, false, &receiver); irr::video::IVideoDriver* driver = device->getVideoDriver(); /*irr::video::SMaterial material; material.FrontfaceCulling = true; driver->setMaterial(material);*/ irr::scene::ISceneManager *sceneManager = device->getSceneManager(); //On rend invisible le curseur //device->getCursorControl()->setVisible(false); RubicCube *cube = new RubicCube(sceneManager); irr::scene::IMeshSceneNode *c_centre = sceneManager->addCubeSceneNode(BLOC_S, 0, 33, irr::core::vector3df(0, 0, 0)); c_centre->setMaterialType(irr::video::EMT_SOLID); c_centre->setMaterialTexture(0, driver->getTexture("E:\\Codage\\Rubirrks\\Ressources\\blue.jpg")); irr::scene::IMeshSceneNode *c_up = sceneManager->addCubeSceneNode(BLOC_S, 0, 34, irr::core::vector3df(-(BLOC_S+BLOC_SPC), 0, 0)); c_up->setMaterialType(irr::video::EMT_SOLID); c_up->setMaterialTexture(0, driver->getTexture("E:\\Codage\\Rubirrks\\Ressources\\red.jpg")); irr::scene::IMeshSceneNode *c_down = sceneManager->addCubeSceneNode(BLOC_S, 0, 35, irr::core::vector3df(BLOC_S+BLOC_SPC, 0, 0)); c_down->setMaterialType(irr::video::EMT_SOLID); c_down->setMaterialTexture(0, driver->getTexture("E:\\Codage\\Rubirrks\\Ressources\\red.jpg")); irr::scene::IMeshSceneNode *c_north = sceneManager->addCubeSceneNode(BLOC_S, 0, 36, irr::core::vector3df(0, BLOC_S+BLOC_SPC, 0)); c_north->setMaterialType(irr::video::EMT_SOLID); c_north->setMaterialTexture(0, driver->getTexture("E:\\Codage\\Rubirrks\\Ressources\\red.jpg")); irr::scene::IMeshSceneNode *c_south = sceneManager->addCubeSceneNode(BLOC_S, 0, 37, irr::core::vector3df(0, -(BLOC_S+BLOC_SPC), 0)); c_south->setMaterialType(irr::video::EMT_SOLID); c_south->setMaterialTexture(0, driver->getTexture("E:\\Codage\\Rubirrks\\Ressources\\red.jpg")); irr::scene::IMeshSceneNode *c_east = sceneManager->addCubeSceneNode(BLOC_S, 0, 38, irr::core::vector3df(0, 0, BLOC_S+BLOC_SPC)); c_east->setMaterialType(irr::video::EMT_SOLID); c_east->setMaterialTexture(0, driver->getTexture("E:\\Codage\\Rubirrks\\Ressources\\red.jpg")); irr::scene::IMeshSceneNode *c_west = sceneManager->addCubeSceneNode(BLOC_S, 0, 39, irr::core::vector3df(0, 0, -(BLOC_S+BLOC_SPC))); c_west->setMaterialType(irr::video::EMT_SOLID); c_west->setMaterialTexture(0, driver->getTexture("E:\\Codage\\Rubirrks\\Ressources\\red.jpg")); irr::scene::IMeshSceneNode *c_111 = sceneManager->addCubeSceneNode(BLOC_S, c_down, 40, irr::core::vector3df(0, -(BLOC_S+BLOC_SPC), -(BLOC_S+BLOC_SPC))); c_111->setMaterialType(irr::video::EMT_SOLID); c_111->setMaterialTexture(0, driver->getTexture("E:\\Codage\\Rubirrks\\Ressources\\blue.jpg")); irr::scene::IMeshSceneNode *c_121 = sceneManager->addCubeSceneNode(BLOC_S, c_down, 41, irr::core::vector3df(0, -(BLOC_S+BLOC_SPC), 0)); c_121->setMaterialType(irr::video::EMT_SOLID); c_121->setMaterialTexture(0, driver->getTexture("E:\\Codage\\Rubirrks\\Ressources\\blue.jpg")); irr::scene::IMeshSceneNode *c_131 = sceneManager->addCubeSceneNode(BLOC_S, c_down, 42, irr::core::vector3df(0, -(BLOC_S+BLOC_SPC), BLOC_S+BLOC_SPC)); c_131->setMaterialType(irr::video::EMT_SOLID); c_131->setMaterialTexture(0, driver->getTexture("E:\\Codage\\Rubirrks\\Ressources\\blue.jpg")); /*irr::scene::IMesh *cubeMesh = sceneManager->getMesh("E:\\Codage\\Rubirrks\\Ressources\\cube.irrmesh"); irr::scene::IMeshSceneNode *c_test = sceneManager->addMeshSceneNode(cubeMesh, 0, 99, irr::core::vector3df(0, 100, 100)); IMesh *cubedMesh = sceneManager->getMesh("E:\\Codage\\Rubirrks\\cube.irrmesh"); IMeshSceneNode *meshtest = sceneManager->addOctTreeSceneNode(cubedMesh, 0, 888); meshtest->setPosition(vector3df(0, 200, 0)); */ //sceneManager->setAmbientLight(irr::video::SColorf(1.0, 1.0, 1.0, 0.0)); irr::scene::ICameraSceneNode *camera; camera = sceneManager->addCameraSceneNodeMaya(0, 100.0f, 200.0f, 2000.0f, 77); //camera = sceneManager->addCameraSceneNode(cube->getRubicElt(1, 1, 1)->anode, vector3df(100, 0, 0), vector3df(0, 0, 50)); ISceneCollisionManager *colisionManager = sceneManager->getSceneCollisionManager(); //ISceneNode *node = cube->getRubicElt(2, 2, 2)->node; //IAnimatedMeshSceneNode *node = cube->getRubicElt(2, 2, 2)->anode; //scene::ITriangleSelector* selector = 0; //selector = sceneManager->createTriangleSelector(node); //selector = sceneManager->createTriangleSelectorFromBoundingBox(node); // node->setTriangleSelector(selector); //selector->drop(); //La chaine pour le titre de la fenetre irr::core::vector3df posCam; core::position2d<s32> posCursor = device->getCursorControl()->getPosition(); /*** essay gestion colision mouse cube ***/ irr::core::line3d<float> collRay; collRay = colisionManager->getRayFromScreenCoordinates(posCursor, sceneManager->getActiveCamera()); // get the collision core::vector3df collPoint; core::triangle3df collTriangle; IAnimatedMeshSceneNode *node = 0; const scene::ISceneNode* pNode = 0; //pNode = colisionManager->getSceneNodeAndCollisionPointFromRay(collRay, collPoint, collTriangle); /****************************************/ wchar_t titre[100]; bool hasCollision = false; int i = 0; //La boucle de rendu while(device->run()){ posCam = camera->getPosition(); posCursor = device->getCursorControl()->getPosition(); swprintf(titre, 100, L"FPS : %d (mode debug) | PosCam : " "X : %f Y : %f Z : %f, m.X : %ld m.Y : %ld", driver->getFPS(), posCam.X, posCam.Y, posCam.Z, posCursor.X, posCursor.Y); device->setWindowCaption(titre); collRay = colisionManager->getRayFromScreenCoordinates(posCursor, sceneManager->getActiveCamera()); for(int i = 0; i < 3; i++){ //if(hasCollision) break; for(int j = 0; j < 3; j++){ //if(hasCollision) break; for(int k = 0; k < 3; k++){ //if(hasCollision) break; node = cube->getRubicElt(i, j, k)->anode; hasCollision = colisionManager->getCollisionPoint(collRay, node->getTriangleSelector(), collPoint, collTriangle, pNode); if(hasCollision && pNode->isTrulyVisible() && !sceneManager->isCulled(pNode)){ //fprintf(stdout, "ID : %ld\n", pNode->getID()); fprintf(stdout, "collPoint.X : %f, collPoint.Y : %f, collPoint.Z : %f\n,", collPoint.X, collPoint.Y, collPoint.Z); //hasCollision = false; //pNode->setMaterialFlag(video::EMF_LIGHTING, receiver.GetMouseState().LeftButtonDown); cube->getRubicElt(i, j, k)->anode->setMaterialFlag(video::EMF_WIREFRAME, receiver.GetMouseState().RightButtonDown); //cube->getRubicElt(i, j, k)->anode->setMaterialFlag(video::EMF_LIGHTING, receiver.GetMouseState().RightButtonDown); //cube->rotate(cube->getRubicElt(1, 1, 1), vector3df(0, 0, 0)); } } } } //hasCollision = false; //collRay = colisionManager->getRayFromScreenCoordinates(posCursor, sceneManager->getActiveCamera()); //oui = colisionManager->getCollisionPoint(collRay, node->getTriangleSelector(), collPoint, collTriangle, pNode); //if(oui){ // //printf("YYYYYYYEEEEEEAAAAAAHHHHHH\n\n"); // fprintf(stdout, "ID : %ld\n", pNode->getID()); // oui = false; //} //printf("posCur.X : %ld, posCur.Y : %ld,, posNode.X : %ld, posNode.Y : %ld\n", posCursor.X, posCursor.Y, posNode.X, posNode.Y); driver->beginScene(true, true, irr::video::SColor(0, 50, 70, 50)); //c_down->setRotation(irr::core::vector3df(i*2.f, 0, 0)); i++; sceneManager->drawAll(); driver->endScene (); device->sleep(20); } device->drop(); return 0; }