Gaze::Gaze(Joint *head, Joint *lefteye, Joint *righteye) : m_head(head), m_leye(lefteye), m_reye(righteye), m_aux_leye(0), m_aux_reye(0), m_headpitch(0), m_targetIsSet(false), m_gazeaux_res(0) { Horde3D::Vec3f p,r,s; //clear rotations lefteye->update(); s = lefteye->getScale(); p = lefteye->getTranslation(); h3dSetNodeTransform( lefteye->getHordeID(), p.x,p.y,p.z, Config::getParamF(IK_Param::DfltEyeRotX_F), Config::getParamF(IK_Param::DfltEyeRotY_F), Config::getParamF(IK_Param::DfltEyeRotZ_F), s.x,s.y,s.z ); righteye->update(); s = righteye->getScale(); p = righteye->getTranslation(); h3dSetNodeTransform( righteye->getHordeID(), p.x,p.y,p.z, Config::getParamF(IK_Param::DfltEyeRotX_F), Config::getParamF(IK_Param::DfltEyeRotY_F), Config::getParamF(IK_Param::DfltEyeRotZ_F), s.x,s.y,s.z ); //Generating 2 auxiliary eye nodes which will help us detrmine the orientation of each eye. #ifdef IK_DEBUG m_aux_leye = createGazeAux(lefteye, "gazeaux.scene.xml", "models/gazeaux/"); //WARNING, requires external gazeaux file m_aux_reye = createGazeAux(righteye, "gazeaux.scene.xml", "models/gazeaux/"); //WARNING, requires external gazeaux file #else m_aux_leye = createGazeAux(lefteye); m_aux_reye = createGazeAux(righteye); #endif //making a small position offset between the eye and the eyeaux //ASSUMING the eye is oriented (1,0,0) //Setting the auxiliar eye joint (in)visible #ifdef IK_DEBUG s = m_leye->getAbsScale(); h3dSetNodeTransform( m_aux_leye->getHordeID(), 0.5f, 0, 0, 0, 0, 0, 4.0f/s.x, 0.2f/s.y, 0.2f/s.z ); h3dSetNodeFlags( m_aux_leye->getHordeID(), 0, true ); s = m_reye->getAbsScale(); h3dSetNodeTransform( m_aux_reye->getHordeID(), 0.5f, 0, 0, 0, 0, 0, 4.0f/s.x, 0.2f/s.y, 0.2f/s.z ); h3dSetNodeFlags( m_aux_reye->getHordeID(), 0, true ); #else h3dSetNodeTransform( m_aux_leye->getHordeID(), 0.5f, 0, 0, 0, 0, 0, 1, 1, 1 ); h3dSetNodeFlags( m_aux_leye->getHordeID(), H3DNodeFlags::Inactive, true ); h3dSetNodeTransform( m_aux_reye->getHordeID(), 0.5f, 0, 0, 0, 0, 0, 1, 1, 1 ); h3dSetNodeFlags( m_aux_reye->getHordeID(), H3DNodeFlags::Inactive, true ); #endif if(m_head > 0 && m_leye > 0 && m_reye > 0 && m_aux_leye > 0 && m_aux_reye > 0) GameLog::logMessage( "IKComponent loaded and initialized"); else GameLog::errorMessage( "IKComponent: gaze failed to initialize" ); //Chek for missing DOFR information if(m_head->getDOFR()->isWeak()) m_head->setDOFR(DOFRestrictions::HEAD); if(m_leye->getDOFR()->isWeak()) m_leye->setDOFR(DOFRestrictions::LEFT_EYE); if(m_reye->getDOFR()->isWeak()) m_reye->setDOFR(DOFRestrictions::RIGHT_EYE); }
void SceneGraphComponent::setSerializedState(GameState& state) { int nodeFlags; if (state.readInt32(&nodeFlags)) return; if (m_hordeID > 0) { h3dSetNodeFlags(m_hordeID, nodeFlags, true ); } float read_transformation[16]; for (int i = 0; i < 16; i++) { if (state.readFloat(&read_transformation[i])) return; } setTransformation(read_transformation); // set last transformation (i. e. one frame ago) for (int i = 0; i < 16; i++) { if (state.readFloat(&read_transformation[i])) return; } memcpy(m_net_lasttransformation, read_transformation, sizeof(float) * 16); // calculate trajectory Vec3f t, r, s, lt, lr, ls; Matrix4f(m_transformation).decompose(t, r, s); Matrix4f(m_net_lasttransformation).decompose(lt, lr, ls); if ((s != ls) || (r != lr) || (t != lt)) { if ((t - lt).length() > m_net_maxTrajection) { m_net_traject_translation.x = 0; m_net_traject_translation.y = 0; m_net_traject_translation.z = 0; m_net_traject_rotation.x = 0; m_net_traject_rotation.y = 0; m_net_traject_rotation.z = 0; m_net_traject_scale.x = 0; m_net_traject_scale.y = 0; m_net_traject_scale.z = 0; } else { m_net_traject_translation = t - lt; m_net_traject_rotation = r - lr; m_net_traject_scale = s - ls; } m_net_applyTrajection = true; } else m_net_applyTrajection = false; float remotefps; if (state.readFloat(&remotefps)) // to be able to traject accordingly to remote speed (reduces entity "jumping") return; m_net_traject_speedup = remotefps / GameEngine::FPS(); //printf("speedup = %f\n", m_net_traject_speedup); }
void SceneGraphComponent::setEnabled(bool enable) { if (m_hordeID > 0) { // Not sure if we want to use recursive == true or false here // Also not sure about the visibility state h3dSetNodeFlags(m_hordeID, enable ? 0 : H3DNodeFlags::Inactive, true ); } }
static Model makeModelCB() { H3DNodeModel nm; nm.n = h3dAddNodes(H3DRootNode, modelRes); h3dSetNodeFlags(nm.n, H3DNodeFlags::NoCastShadow, true); LOG("Created node %d.", nm.n); return nm.m; } // end makeModelCB
void QSceneNode::setEnabled(bool enabled) { h3dSetNodeFlags(m_hordeID, enabled ? 0 : H3DNodeFlags::Inactive, true ); m_active = enabled; }
H3DView(int winWidth, int winHeight) : BulletEngineTest(), //model(0), cam(0), frameNum(0), text(NULL), textLen(32), _rx(15), _ry(-50), //_rx(0), _ry(0), _prev_x(0), _prev_y(0), _mouseEnteredThisFrame(false) { assert(view == NULL); view = this; text = new char[textLen]; memset(text, 0, textLen); LOG("Initializing Horde3D..."); h3dInit(); h3dSetOption(H3DOptions::MaxAnisotropy, 8); h3dSetOption(H3DOptions::SampleCount, 16); //h3dSetOption(H3DOptions::WireframeMode, 1); //h3dSetOption(H3DOptions::DebugViewMode, 1); h3dSetOption(H3DOptions::GatherTimeStats, 1); LOG("Declaring resources..."); pipeRes = h3dAddResource(H3DResTypes::Pipeline, "pipelines/forward.pipeline.xml", 0); H3DRes skyBoxRes = h3dAddResource(H3DResTypes::SceneGraph, "models/skybox/skybox.scene.xml", 0); //modelRes = h3dAddResource(H3DResTypes::SceneGraph, "models/AssJacket/AssJacket.scene.xml", 0); //modelRes = h3dAddResource(H3DResTypes::SceneGraph, "models/ares/ares.scene.xml", 0); modelRes = h3dAddResource(H3DResTypes::SceneGraph, "models/man/man.scene.xml", 0); fontMatRes = h3dAddResource(H3DResTypes::Material, "overlays/font.material.xml", 0); panelMatRes = h3dAddResource(H3DResTypes::Material, "overlays/panel.material.xml", 0); LOG("Loading resources from disk..."); h3dutLoadResourcesFromDisk("/home/whitelynx/devel/other/Horde3D/build-make/Binaries/Content" "|/home/whitelynx/devel/skewedaspect/precursors-client/resources/content"); LOG("Building scene..."); /* // Add model to scene model = h3dAddNodes(H3DRootNode, modelRes); h3dSetNodeTransform(model, 0, 0, -500, // Translation 0, 0, 0, // Rotation 1, 1, 1 // Scale ); */ // Add light source H3DNode light = h3dAddLightNode(H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP"); // Set light position and radius h3dSetNodeTransform(light, 0, 20, 0, 0, 0, 0, 10, 10, 10 ); h3dSetNodeParamF(light, H3DLight::RadiusF, 0, 50.0f); LOG("Setting up camera..."); cam = h3dAddCameraNode(H3DRootNode, "Camera", pipeRes); resizeViewport(winWidth, winHeight); #if 1 H3DNode sky = h3dAddNodes(H3DRootNode, skyBoxRes); h3dSetNodeTransform(sky, 0, 0, 0, // Translation 0, 0, 0, // Rotation 210, 50, 210 // Scale ); h3dSetNodeFlags(sky, H3DNodeFlags::NoCastShadow, true); #endif LOG("Setting BulletEngine callbacks..."); setMakeModelCallback(&makeModelCB); setUpdateModelCallback(&updateModelCB); LOG("Initializing physics..."); initPhysics(); LOG("Ready."); } // end H3DView