void SceneCamera::CenterCameraOn(NodePath np) { if (_useTrackball) _window->center_trackball(np); else { _centeringCamera = true; _objectivePos = np.get_pos(_window->get_render()); _objectivePos.set_z(_objectivePos.get_z() + _camera_height); LPoint3f cameraRot = _camera.get_hpr(); float rad2deg = 3.1415926535897 / 180; cameraRot.set_x(cameraRot.get_x() * rad2deg); cameraRot.set_y(cameraRot.get_y() * rad2deg); cameraRot.set_z(cameraRot.get_z() * rad2deg); _objectivePos.set_x(np.get_x() + sin(cameraRot.get_x()) * 100); _objectivePos.set_y(np.get_y() + tan(cameraRot.get_y()) * 100); if (_currentCameraAngle == 1) _objectivePos.set_y(_objectivePos.get_y() + 80 + (140 - _camera_height) / 1.35); else { _objectivePos.set_x(_objectivePos.get_x() + 25 - (_camera_height - 50) * 0.85); _objectivePos.set_y(_objectivePos.get_y() + 40 - (_camera_height - 50) * 1); } } }
void ObserverNodePath::setNodePathTo(osg::Node* node) { if (node) { NodePathList nodePathList = node->getParentalNodePaths(); if (nodePathList.empty()) { NodePath nodePath; nodePath.push_back(node); setNodePath(nodePath); } else { if (nodePathList[0].empty()) { nodePathList[0].push_back(node); } setNodePath(nodePathList[0]); } } else { clearNodePath(); } }
void WaypointGenerator::Leveling(void) { float step = 0; float steps = object->waypoints.size(); for (unsigned int it = 0 ; it < object->waypoints.size() ; ++it) { unsigned int attempts = 0; Waypoint* wp = object->waypoints[it]; NodePath np = wp->nodePath; while (LevelWaypoint(wp) == false && attempts < 3) { if (attempts % 2) np.set_x(np.get_x() + 0.01); else np.set_y(np.get_y() + 0.01); ++attempts; } if (attempts == 3) { it--; world->DeleteWayPoint(wp); } UpdateProgress("Waypoint Leveling (4/4): %p%", ++step / steps * 100); } }
void SoftBody::_add_pinned_point(int p_point_index, const NodePath &p_spatial_attachment_path) { SoftBody::PinnedPoint *pinned_point; if (-1 == _get_pinned_point(p_point_index, pinned_point)) { // Create new PinnedPoint pp; pp.point_index = p_point_index; pp.spatial_attachment_path = p_spatial_attachment_path; if (!p_spatial_attachment_path.is_empty() && has_node(p_spatial_attachment_path)) { pp.spatial_attachment = Object::cast_to<Spatial>(get_node(p_spatial_attachment_path)); pp.offset = (pp.spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer::get_singleton()->soft_body_get_point_global_position(physics_rid, pp.point_index)); } pinned_points.push_back(pp); } else { pinned_point->point_index = p_point_index; pinned_point->spatial_attachment_path = p_spatial_attachment_path; if (!p_spatial_attachment_path.is_empty() && has_node(p_spatial_attachment_path)) { pinned_point->spatial_attachment = Object::cast_to<Spatial>(get_node(p_spatial_attachment_path)); pinned_point->offset = (pinned_point->spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer::get_singleton()->soft_body_get_point_global_position(physics_rid, pinned_point->point_index)); } } }
void accumulate(const NodePath& nodePath) { if (nodePath.empty()) return; unsigned int i = 0; if (_ignoreCameras) { // we need to found out the last absolute Camera in NodePath and // set the i index to after it so the final accumulation set ignores it. i = nodePath.size(); NodePath::const_reverse_iterator ritr; for(ritr = nodePath.rbegin(); ritr != nodePath.rend(); ++ritr, --i) { const osg::Camera* camera = dynamic_cast<const osg::Camera*>(*ritr); if (camera && (camera->getReferenceFrame()!=osg::Transform::RELATIVE_RF || camera->getParents().empty())) { break; } } } // do the accumulation of the active part of nodepath. for(; i<nodePath.size(); ++i) { const_cast<Node*>(nodePath[i])->accept(*this); } }
NodePath SceneGraphManipulator::getNodePath() const { NodePath nodePath; ObserveredNodePath::const_iterator itr = _trackNodePath.begin(); for(; itr != _trackNodePath.end(); ++itr) nodePath.push_back(const_cast<Node*>(itr->get())); return nodePath; }
// Disables freelook and places the camera in a good position to // demonstrate the billboard effect void World::set_view_billboard(const Event* event) { // Note: detach the trackball from the mouse to disable it m_trackball.detach_node(); const NodePath& render = m_windowFramework->get_render(); NodePath camera = m_windowFramework->get_camera_group(); camera.reparent_to(render); camera.set_pos_hpr(-7, 7, 0, -90, 0, 0); }
// Enables freelook void World::set_view_main(const Event* event) { const NodePath& render = m_windowFramework->get_render(); NodePath camera = m_windowFramework->get_camera_group(); camera.reparent_to(render); // Note: reparent the trackball to the mouse to enable it const NodePath& mouse = m_windowFramework->get_mouse(); m_trackball.reparent_to(mouse); }
OpState OpBreakAtPoints::GetState(String_256* UIDescription, OpDescriptor*) { OpState OpSt; String_256 DisableReason; OpSt.Greyed = FALSE; BOOL FoundSelected = FALSE; // Go through the selection until we find a selected point SelRange* Selected = GetApplication()->FindSelection(); Node* pNode = Selected->FindFirst(); while (pNode) { if (IS_A(pNode,NodePath) || IS_A(pNode,NodeBlendPath)) { NodePath* pNodePath = (NodePath*)pNode; INT32 NumSplinters = pNodePath->InkPath.NumSplinters(); if (NumSplinters > 0) { // We need to ask the effected nodes if they (and their parents) can handle this node being replaced ObjChangeFlags cFlags; if (NumSplinters > 1) cFlags.MultiReplaceNode = TRUE; // Node will be replaced with more than one node. else cFlags.ReplaceNode = TRUE; // Node will be replaced with one node only. String_32 optokenstring(OPTOKEN_BREAKATPOINTS); ObjChangeParamWithToken ObjChange(OBJCHANGE_STARTING,cFlags,pNodePath,NULL,&optokenstring); // Will the node allow this op to happen? if (pNodePath->AllowOp(&ObjChange,FALSE)) { FoundSelected = TRUE; break; } } } pNode = Selected->FindNext(pNode); } // The operation is disabled if there are no complex paths selected if (!FoundSelected) { OpSt.Greyed = TRUE; DisableReason = String_256(_R(IDS_NEEDS_SELECTED_POINT)); *UIDescription = DisableReason; } return(OpSt); }
void Pathfinder::getPath(AStarNode *node, NodePath &path) { while(node != NULL) { path.push_back(node->position); node = node->parent; } reverse(path.begin(), path.end()); }
std::string NodePathFullName(NodePath nodepath, NodePath root) { NodePath cur = nodepath.get_parent(); std::string name = nodepath.get_name(); while (cur != root) { name = cur.get_name() + '/' + name; cur = cur.get_parent(); } return (name); }
void WorldFlattener::FlattenObjects(MapObject* first, MapObject* second) { NodePath target = first->render; LPoint3f relative_position = second->nodePath.get_pos(target); LPoint3f relative_hpr = second->nodePath.get_hpr(target); second->render.reparent_to(target); second->render.set_pos(relative_position); second->render.set_hpr(relative_hpr); target.clear_model_nodes(); target.flatten_strong(); second->render = target; }
void Dijkstra::save_path(Node* start, Node* dest) { NodePath* path = new NodePath; Node* current_node = dest; if (current_node->get_cost_from_start() == max_cost) { saved_paths[NodePair(start, dest)] = path; return; } while (start != current_node) { path->push_back(current_node); current_node = current_node->get_parent(); } saved_paths[NodePair(start, dest)] = path; }
/** * @brief Constructs a new TagStateManager * @details This constructs a new TagStateManager. The #main_cam_node should * refer to the main scene camera, and will most likely be base.cam. * It is necessary to pass the camera because the C++ code does not have * access to the showbase. * * @param main_cam_node The main scene camera */ TagStateManager::TagStateManager(NodePath main_cam_node) { nassertv(!main_cam_node.is_empty()); nassertv(DCAST(Camera, main_cam_node.node()) != NULL); _main_cam_node = main_cam_node; // Set default camera mask DCAST(Camera, _main_cam_node.node())->set_camera_mask(BitMask32::bit(1)); // Init containers _containers["shadow"] = StateContainer("Shadows", 2, false); _containers["voxelize"] = StateContainer("Voxelize", 3, false); _containers["envmap"] = StateContainer("Envmap", 4, true); _containers["forward"] = StateContainer("Forward", 5, true); }
/** * @brief Applies a given state to a NodePath * @details This applies a shader to the given NodePath which is used when the * NodePath is rendered by any registered camera of the container. * * @param container The container which is used to store the state * @param np The nodepath to apply the shader to * @param shader A handle to the shader to apply * @param name Name of the state, should be a unique identifier * @param sort Changes the sort with which the shader will be applied. */ void TagStateManager::apply_state(StateContainer& container, NodePath np, Shader* shader, const string &name, int sort) { if (tagstatemgr_cat.is_spam()) { tagstatemgr_cat.spam() << "Constructing new state " << name << " with shader " << shader << endl; } // Construct the render state CPT(RenderState) state = RenderState::make_empty(); // Disable color write for all stages except the environment container if (!container.write_color) { state = state->set_attrib(ColorWriteAttrib::make(ColorWriteAttrib::C_off), 10000); } state = state->set_attrib(ShaderAttrib::make(shader, sort), sort); // Emit a warning if we override an existing state if (container.tag_states.count(name) != 0) { tagstatemgr_cat.warning() << "Overriding existing state " << name << endl; } // Store the state, this is required whenever we attach a new camera, so // it can also track the existing states container.tag_states[name] = state; // Save the tag on the node path np.set_tag(container.tag_name, name); // Apply the state on all cameras which are attached so far for (size_t i = 0; i < container.cameras.size(); ++i) { container.cameras[i]->set_tag_state(name, state); } }
//Sets up some default lighting void World::setup_lights() const { PT(AmbientLight) ambientLightPtr = new AmbientLight("ambientLight"); PT(DirectionalLight) directionalLightPtr = new DirectionalLight("directionalLight"); if(ambientLightPtr == NULL || directionalLightPtr == NULL) { nout << "ERROR: out of memory." << endl; return; } ambientLightPtr->set_color(Colorf(.4,.4,.35,1)); directionalLightPtr->set_direction(LVector3f(0,8,-2.5)); directionalLightPtr->set_color(Colorf(0.9,0.8,0.9,1)); NodePath renderNp = m_windowFrameworkPtr->get_render(); renderNp.set_light(renderNp.attach_new_node(directionalLightPtr)); renderNp.set_light(renderNp.attach_new_node(ambientLightPtr)); }
NodePath TreeSearcher::FindPath(Node* src, Node* dest) { src = src ? src : this->src; dest = dest ? dest : this->dest; std::deque<Node *> srcQueue; std::stack<Node *> destStack; NodePath path; Node *currentNode = src; while (currentNode) { srcQueue.push_back(currentNode); currentNode = currentNode -> Parent(); } currentNode = dest; while(currentNode) { destStack.push(currentNode); currentNode = currentNode -> Parent(); } Node* common; while(srcQueue.size() > 1 && destStack.size() > 1 && srcQueue.back() == destStack.top()) { common = destStack.top(); srcQueue.pop_back(); destStack.pop(); } if (srcQueue.back() == destStack.top()) { common = destStack.top(); if (srcQueue.size() > 1) srcQueue.pop_back(); else if (destStack.size() > 1) destStack.pop(); } for(Node *node : srcQueue) { path.AddPathNode(node); } if (common != src && common != dest) path.AddPathNode(common); while (!destStack.empty()) { path.AddPathNode(destStack.top()); destStack.pop(); } return path; }
void Character::initNodePath(Player *player, CollisionTraverser *traverser, CollisionTraverser *traverserQueue, CollisionHandlerQueue *colliHandlerQueue, Filename charDir, Filename charWalkDir, Filename charStandDir, std::string lodNodename, std::string colliNodeName) { LODNode *lod = new LODNode(lodNodename); NodePath lodNodePath(lod); lodNodePath.reparent_to(player->getWindow()->get_render()); lod->add_switch(50, 0); // load character and place on the grounds NodePath character = player->getWindow()->load_model(player->getPanda()->get_models(), charDir); character.reparent_to(lodNodePath); character.set_scale(0.203, 0.203, 0.203); // add collision node to character CollisionNode *collNode = new CollisionNode(colliNodeName); collNode->add_solid(new CollisionSphere(0, 0, 0, 2.5)); NodePath fromObj = character.attach_new_node(collNode); CollisionHandlerPusher *colliHandlerPusher = new CollisionHandlerPusher(); colliHandlerPusher->add_collider(fromObj, character); traverser->add_collider(fromObj, colliHandlerPusher); traverserQueue->add_collider(fromObj, colliHandlerQueue); // Load the walk animation player->getWindow()->load_model(character, charStandDir); player->getWindow()->load_model(character, charWalkDir); // bind animation auto_bind(character.node(), animCollection); stopMoving(); nodePath = character; standAnimName = animCollection.get_anim_name(0); walkAnimName = animCollection.get_anim_name(1); // get animation names //for(int i = 0; i < animCollection.get_num_anims(); i++) // cout << animCollection.get_anim_name(i) << endl; }
bool AnimatedObject::LoadAnimation(const std::string& name) { NodePath root = GetNodePath(); NodePath np = _window->load_model(root, ANIMATION_PATH(_modelName, name)); string controlName; if (np.get_error_type() != NodePath::ET_ok) { std::cout << "Can't load anim " << name << " for " << _modelName << std::endl; return (false); } auto_bind(root.node(), _anims, 0xf); np.detach_node(); controlName = _anims.get_anim_name(_anims.get_num_anims() - 1); _mapAnims.insert(_mapAnims.end(), pair<string, AnimControl*>(name, _anims.find_anim(controlName))); return (true); }
void Sunlight::InitializeSun() { NodePath sun_root = world.floors_node; if (static_sunlight.is_null()) static_sunlight = new DirectionalLight("sunlight"); sunlight_node = static_sunlight; sunlight_nodepath = sun_root.attach_new_node(sunlight_node); NodePath sphere = sunlight_nodepath.attach_new_node("sun-representation"); static_sunlight->show_frustum(); world.model_sphere.copy_to(sphere); sphere.set_scale(10); sunlight_nodepath.reparent_to(sphere); sunlight_nodepath.show(); }
/******************************************************************************************** > BOOL OpMenuSelectPathPoints::DoAction(BOOL SelectPoints) Author: Peter_Arnold (Xara Group Ltd) <*****@*****.**> Created: 30/04/95 Inputs: SelectPoints - TRUE to select all the points in the path - FALSE to deslect all the points in the path Outputs: - Returns: TRUE/FALSE for success/failure Purpose: Common code for selecting or deselecting all the points in all the selected paths. SeeAlso: - ********************************************************************************************/ BOOL OpMenuSelectPathPoints::DoAction(BOOL SelectPoints) { SelRange* pSelection = GetApplication()->FindSelection(); Node* pNode = pSelection->FindFirst(); // Cycle through all the selected paths while (pNode != NULL) { if (pNode->IsNodePath()) { NodePath* pPath = (NodePath*)pNode; Spread* pSpread = pNode->FindParentSpread(); ERROR2IF(pSpread == NULL, FALSE, "NodePath didn't have a parent spread"); // Remove the blobs from the path RenderRegion* pRegion = DocView::RenderOnTop(NULL, pSpread, ClippedEOR); while (pRegion != NULL) { pPath->RenderObjectBlobs(pRegion); pRegion = DocView::GetNextOnTop(NULL); } // Set the selection state const INT32 NumCoords = pPath->InkPath.GetNumCoords(); for (INT32 loop = 0; loop<NumCoords; loop++) { pPath->InkPath.GetFlagArray()[loop].IsSelected = SelectPoints; } // Put the blobs back on the path pRegion = DocView::RenderOnTop(NULL, pSpread, ClippedEOR); while (pRegion != NULL) { pPath->RenderObjectBlobs(pRegion); pRegion = DocView::GetNextOnTop(NULL); } GetApplication()->UpdateSelection(); } pNode = pSelection->FindNext(pNode); } return TRUE; }
// Updates the shader inputs that need to be updated every frame. // Normally, you shouldn't call this, it's being called in a task. void CCommonFilters::update() { if(m_configuration["VolumetricLighting"] != NULL) { NodePath caster = static_cast<VolumetricLightingConfiguration*> (m_configuration["VolumetricLighting"])->caster; LPoint2f casterpos; NodePath cameraNp = m_manager.m_camera; PT(Camera) camera = DCAST(Camera, cameraNp.node()); camera->get_lens()->project(caster.get_pos(cameraNp), casterpos); m_finalQuad.set_shader_input("casterpos", LVector4f(casterpos.get_x() * 0.5 + 0.5, casterpos.get_y() * 0.5 + 0.5, 0, 0)); } }
bool Node::has_node_and_resource(const NodePath& p_path) const { if (!has_node(p_path)) return false; Node *node = get_node(p_path); if (p_path.get_subname_count()) { RES r; for(int j=0;j<p_path.get_subname_count();j++) { r = j==0 ? node->get(p_path.get_subname(j)) : r->get(p_path.get_subname(j)); if (r.is_null()) return false; } } return true; }
SceneCamera::SceneCamera(WindowFramework* window, NodePath camera) : _window(window), _graphicWindow(window->get_graphics_window()), _camera(camera) { _useTrackball = false; _scrollEnabled = true; RefreshCameraHeight(); _destHeight = _camera_height; camera.set_pos(0, 0, _camera_height); camera.set_hpr(-40, -40, 0); _cameraMovementSpeed = 30.f; _currentCameraAngle = 0; _currentHpr = cameraAngles[_currentCameraAngle]; _objectiveHpr = _currentHpr; _minPosX = _minPosY = _maxPosX = _maxPosY = 0; _followingNodePath = false; _centeringCamera = false; }
void World::make_tv_man(float x, float y, float z, Texture* tex, float playrate) { CActor man; CActor::AnimMap manAnim; manAnim["../models/mechman_idle"].push_back("mechman_anim"); man.load_actor(m_windowFramework, "../models/mechman_idle", &manAnim, PartGroup::HMF_ok_part_extra | PartGroup::HMF_ok_anim_extra | PartGroup::HMF_ok_wrong_root_name); man.set_pos(x, y, z); const NodePath& render = m_windowFramework->get_render(); man.reparent_to(render); NodePath fp = man.find("**/faceplate"); fp.set_texture(tex, 1); man.find_anim("mechman_anim")->set_play_rate(playrate); const bool restart = true; man.loop("mechman_anim", restart); m_tvMen.push_back(man); }
NodePath NodePath::rel_path_to(const NodePath &p_np) const { ERR_FAIL_COND_V(!is_absolute(), NodePath()); ERR_FAIL_COND_V(!p_np.is_absolute(), NodePath()); Vector<StringName> src_dirs = get_names(); Vector<StringName> dst_dirs = p_np.get_names(); //find common parent int common_parent = 0; while (true) { if (src_dirs.size() == common_parent) break; if (dst_dirs.size() == common_parent) break; if (src_dirs[common_parent] != dst_dirs[common_parent]) break; common_parent++; } common_parent--; Vector<StringName> relpath; for (int i = src_dirs.size() - 1; i > common_parent; i--) { relpath.push_back(".."); } for (int i = common_parent + 1; i < dst_dirs.size(); i++) { relpath.push_back(dst_dirs[i]); } if (relpath.size() == 0) relpath.push_back("."); return NodePath(relpath, p_np.get_subnames(), false, p_np.get_property()); }
bool ObserverNodePath::getNodePath(NodePath& nodePath) const { #ifndef EMSCRIPTEN OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); #endif //EMSCRIPTEN nodePath.resize(_nodePath.size()); for(unsigned int i=0; i<_nodePath.size(); ++i) { if (_nodePath[i].valid()) { nodePath[i] = _nodePath[i].get(); } else { OSG_NOTICE<<"ObserverNodePath::getNodePath() node has been invalidated"<<std::endl; nodePath.clear(); return false; } } return true; }
void Mouse::Run(void) { PStatCollector collector("Level:Mouse:Run"); collector.start(); //if (pointer.get_in_window()) { LPoint2f cursorPos = GetPositionRatio(); if (cursorPos != _lastMousePos) { _lastMousePos = cursorPos; _pickerRay->set_from_lens(_window->get_camera(0), cursorPos.get_x(), cursorPos.get_y()); _collisionTraverser.traverse(_window->get_render()); _collisionHandlerQueue->sort_entries(); //_hovering.Reset(); _hovering.hasDynObject = false; _hovering.dynObject = NodePath(); for (int i = 0 ; i < _collisionHandlerQueue->get_num_entries() ; ++i) { CollisionEntry* entry = _collisionHandlerQueue->get_entry(i); NodePath into = entry->get_into_node_path(); if (into.is_hidden()) continue ; switch (into.get_collide_mask().get_word()) { case ColMask::DynObject: if (!(_hovering.hasDynObject)) _hovering.SetDynObject(into); break ; } } } } collector.stop(); }
LevelInterface::LevelInterface(WindowFramework* window): m_interface(NodePath("LevelInterface")), m_lifes(new TextNode("lifes")) { m_interface.reparent_to(window->get_render_2d()); hide(); // PT(Texture) tex; tex = TexturePool::load_texture( "resources/gui/lifes.png"); CardMaker cm("cardMaker"); cm.set_frame_fullscreen_quad(); PT(PandaNode) readyCard = cm.generate(); NodePath lifes(readyCard); lifes.set_texture( tex ); lifes.reparent_to(m_interface); lifes.set_scale(0.1, 0.1, 0.05); lifes.set_pos(0.9, 0.8, 0.9); // m_lifes->set_text_color(0.f, 0.f, 1.f, 1.f); m_lifes->set_text("0"); NodePath lifeText = m_interface.attach_new_node(m_lifes); lifeText.set_scale(0.1); lifeText.set_pos(0.91, 0.9, 0.875); }
bool WaypointGenerator::LevelWaypoint(Waypoint* waypoint) { NodePath np; NodePath wp = waypoint->nodePath; LPoint3 min_pos; float new_height = wp.get_z(); { CollisionTraverser col_traverser; PT(CollisionHandlerQueue) col_queue = new CollisionHandlerQueue; PT(CollisionNode) cnode = new CollisionNode("waypoint"); PT(CollisionSegment) segment = new CollisionSegment; cnode->set_from_collide_mask(CollideMask(ColMask::Object)); cnode->add_solid(segment); np = object->nodePath.attach_new_node(cnode); segment->set_point_a(wp.get_x(), wp.get_y(), wp.get_z()); segment->set_point_b(wp.get_x(), wp.get_y(), wp.get_z() - (100000.f)); col_traverser.add_collider(np, col_queue); col_traverser.traverse(object->render); if (col_queue->get_num_entries()) { LPoint3 np_size = NodePathSize(wp); col_queue->sort_entries(); min_pos = col_queue->get_entry(0)->get_surface_point(object->nodePath); new_height = min_pos.get_z() + (np_size.get_y() / 2); } np.remove_node(); if (new_height != wp.get_z(object->nodePath)) { wp.set_z(object->nodePath, new_height); return (true); } return (false); } }