void CVehicleSeatActionRotateTurret::MaintainPartRotationWorldSpace(EVehicleTurretRotationType eType) { CVehiclePartBase* pPart = m_rotations[eType].m_pPart; IVehiclePart* pParent = pPart->GetParent(); IActor* pActor = m_pSeat->GetPassengerActor(); bool remote = m_pSeat->GetCurrentTransition() == IVehicleSeat::eVT_RemoteUsage; bool worldSpace = m_rotations[eType].m_worldSpace && VehicleCVars().v_independentMountedGuns != 0; if (worldSpace && pParent && pActor && pActor->IsClient() && !remote) { // we want to keep the old worldspace rotation // therefore we're updating the local transform from it // NB: there is no need to clamp here, its done later Matrix34 localTM = pParent->GetWorldTM().GetInverted() * Matrix34(m_rotations[eType].m_prevWorldQuat); localTM.OrthonormalizeFast(); // precision issue const Matrix34 &baseTM = pPart->GetLocalBaseTM(); if (!Matrix34::IsEquivalent(baseTM,localTM)) { Ang3 anglesCurr(baseTM); Ang3 angles(localTM); if (eType == eVTRT_Pitch) { angles.y = anglesCurr.y; angles.z = anglesCurr.z; } else if (eType == eVTRT_Yaw) { angles.x = anglesCurr.x; angles.y = anglesCurr.y; } localTM.SetRotationXYZ(angles); localTM.SetTranslation(baseTM.GetTranslation()); pPart->SetLocalBaseTM(localTM); m_pSeat->ChangedNetworkState(CVehicle::ASPECT_PART_MATRIX); } #if ENABLE_VEHICLE_DEBUG if (VehicleCVars().v_debugdraw == eVDB_Parts) { float color[] = {1,1,1,1}; Ang3 a(localTM), aBase(baseTM); gEnv->pRenderer->Draw2dLabel(200,200,1.4f,color,false,"localAng: %.1f (real: %.1f)", RAD2DEG(a.z), RAD2DEG(aBase.z)); } #endif } }
void SpecificWorker::moverpataPunto(QVec pfin) { QVec angles=QVec::zeros(3); QVec p=inner->transform("arm1motor1T",pfin,"base"); float q1=atan(p.x()/p.z()); float x2=p.x()*p.x(),y2=p.y()*p.y(),z2=p.z()*p.z(),Femur2=Femur*Femur,Tibia2=Tibia*Tibia, r=sqrt(x2+z2)-Coxa, cosq3=((r*r)+y2-Tibia2-Femur2)/(2*Tibia*Femur), senq3=-sqrt(1-(cosq3*cosq3)); qDebug()<<"cos (q3) = "<<r*r<<"+"<<y2<<"-"<<Tibia2<<"-"<<Femur2<<")/(2*"<<Tibia<<"*"<<Femur<<")"<<" = "<<cosq3; qDebug()<<"sen (q3) = "<<senq3; float q3=atan(senq3/cosq3); float q2=atan(p.y()/r)-atan((Tibia*senq3)/(Femur+(Tibia*cosq3))); angles(0)=q1; angles(1)=q2+0.22113-0.5; angles(2)=q3+0.578305+0.8; moverangles(angles); }
align::EulerAngles TestMuonReader::toPhiXYZ(const align::RotationType& rot) { align::EulerAngles angles(3); angles(1) = std::atan2(rot.yz(), rot.zz()); angles(2) = std::asin(-rot.xz()); angles(3) = std::atan2(rot.xy(), rot.xx()); return angles; }
AlignTransform::Rotation GlobalPositionRcdWrite::toMatrix(double alpha, double beta, double gamma) { align::EulerAngles angles(3); angles(1) = alpha; angles(2) = beta; angles(3) = gamma; align::RotationType alignRotation = align::toMatrix(angles); return AlignTransform::Rotation(CLHEP::HepRep3x3(alignRotation.xx(), alignRotation.xy(), alignRotation.xz(), alignRotation.yx(), alignRotation.yy(), alignRotation.yz(), alignRotation.zx(), alignRotation.zy(), alignRotation.zz())); }
mat dynamics::getAlphaBetaGamma_R(mat & R) { mat angles(3,1); // BETA angles(2,1) = std::atan2(-R(3, 1), std::sqrt(R(1, 1) * R(1, 1) + R(2, 1) * R(2, 1))); if (cos(angles(2, 1))) { error(" AlphaBetaGamma_R -> Singularity"); } return angles * 0; // NOT IMPLEMENTED ; }
TEST_F(GeneratorsBenchmark, benchmarkHyperbolicGeneratorWithSequentialQuadtree) { count n = 100000; double s = 1.0; double alpha = 1; vector<double> angles(n); vector<double> radii(n); HyperbolicSpace::fillPoints(angles, radii, s, alpha); double R = s*HyperbolicSpace::hyperbolicAreaToRadius(n); double r = HyperbolicSpace::hyperbolicRadiusToEuclidean(R); Quadtree<index> quad(r); for (index i = 0; i < n; i++) { quad.addContent(i, angles[i], radii[i]); } angles.clear(); radii.clear(); quad.trim(); quad.sortPointsInLeaves(); quad.reindex(); quad.extractCoordinates(angles, radii); HyperbolicGenerator gen; Graph G = gen.generate(angles, radii, quad, R); EXPECT_EQ(n, G.numberOfNodes()); }
TEST_F(GeneratorsBenchmark, benchmarkHyperbolicGeneratorWithSortedNodes) { count n = 100000; double s = 1.0; double alpha = 1.0; double t = 1.0; vector<double> angles(n); vector<double> radii(n); double R = s*HyperbolicSpace::hyperbolicAreaToRadius(n); double r = HyperbolicSpace::hyperbolicRadiusToEuclidean(R); //sample points randomly HyperbolicSpace::fillPoints(angles, radii, s, alpha); vector<index> permutation(n); index p = 0; std::generate(permutation.begin(), permutation.end(), [&p](){return p++;}); //can probably be parallelized easily, but doesn't bring much benefit Aux::Parallel::sort(permutation.begin(), permutation.end(), [&angles,&radii](index i, index j){return angles[i] < angles[j] || (angles[i] == angles[j] && radii[i] < radii[j]);}); vector<double> anglecopy(n); vector<double> radiicopy(n); #pragma omp parallel for for (index j = 0; j < n; j++) { anglecopy[j] = angles[permutation[j]]; radiicopy[j] = radii[permutation[j]]; } Graph G = HyperbolicGenerator().generate(anglecopy, radiicopy, r, R*t); EXPECT_EQ(G.numberOfNodes(), n); }
void SAmmoParams::LoadGeometry(const XmlNodeRef& ammoParamsNode) { CGameXmlParamReader reader(ammoParamsNode); XmlNodeRef geometryNode = reader.FindFilteredChild("geometry"); if (!geometryNode) return; CGameXmlParamReader geometryReader(geometryNode); XmlNodeRef firstpersonNode = geometryReader.FindFilteredChild("firstperson"); if (firstpersonNode) { const char *modelName = firstpersonNode->getAttr("name"); if (modelName && modelName[0]) { Ang3 angles(0,0,0); Vec3 position(0,0,0); float scale=1.0f; firstpersonNode->getAttr("position", position); firstpersonNode->getAttr("angles", angles); firstpersonNode->getAttr("scale", scale); fpLocalTM = Matrix34(Matrix33::CreateRotationXYZ(DEG2RAD(angles))); fpLocalTM.ScaleColumn(Vec3(scale, scale, scale)); fpLocalTM.SetTranslation(position); fpGeometryName = modelName; } } }
int main( int argc, char **argv ) { Hubo_Control hubo; std::vector<Vector6d, Eigen::aligned_allocator<Vector6d> > angles(5); // This declares "angles" as a dynamic array of Vector6ds with a starting array length of 5 angles[0] << 0.0556916, 0.577126, 0.0816814, -0.492327, 0, 0; angles[1] << -1.07878, 0.408266, -0.477742, -0.665062, 0, 0; angles[2] << -1.17367, -0.0540511, -0.772141, -0.503859, 0, 0; angles[3] << -0.518417, 0.172191, -0.566084, -0.0727671, 0, 0; angles[4] << 0, 0, 0, 0, 0, 0; // Obviously we could easily set up some code which reads in these values out of a pre-recorded file Vector6d currentPosition; // This Vector6d will be used to track our current angle configuration double tol = 0.075; // This will be the allowed tolerance before moving to the next point int traj = 0; // This will keep track of our current target on the trajectory while( true ) { hubo.update(); // This grabs the latest state information hubo.getLeftArmAngleStates( currentPosition ); // This will fill in the values of "currentPosition" by passing it in by reference // If you are unfamiliar with "passing by reference", let me know and I can explain the concept. It's a feature of C++ but not C if( ( currentPosition-angles[traj] ).norm() < tol ) // The class function .norm() is a feature of the Eigen libraries. Eigen has many other extremely useful functions like this. { traj++; if( traj > 4 ) traj = 0; } hubo.setLeftArmAngles( angles[traj] ); // Notice that the second argument is not passed in, making it default to "false" hubo.sendControls(); // This will send off all the latest control commands over ACH } }
void SpecificWorker::sendData(const TData& data) { QVec angles=QVec::zeros(3); for(auto m:data.axes) { if(m.name=="x") angles(0)=(m.value/65537); if(m.name=="y") angles(1)=(m.value/65537); if(m.name=="z") angles(2)=(m.value/65537); } moverangles(angles); }
// advance camera to next point void Pointfile_Next (void) { if(!s_pointfile.shown()) return; if (s_check_point+2 == s_pointfile.end()) { globalOutputStream() << "End of pointfile\n"; return; } CPointfile::const_iterator i = ++s_check_point; CamWnd& camwnd = *g_pParentWnd->GetCamWnd(); Camera_setOrigin(camwnd, *i); g_pParentWnd->GetXYWnd()->SetOrigin(*i); { Vector3 dir(vector3_normalised(vector3_subtracted(*(++i), Camera_getOrigin(camwnd)))); Vector3 angles(Camera_getAngles(camwnd)); angles[CAMERA_YAW] = static_cast<float>(radians_to_degrees(atan2(dir[1], dir[0]))); angles[CAMERA_PITCH] = static_cast<float>(radians_to_degrees(asin(dir[2]))); Camera_setAngles(camwnd, angles); } }
void SAmmoParams::LoadGeometry() { const IItemParamsNode *geometry = pItemParams->GetChild("geometry"); if (!geometry) { return; } const IItemParamsNode *firstperson = geometry->GetChild("firstperson"); if (firstperson) { const char *modelName = firstperson->GetAttribute("name"); if (modelName && modelName[0]) { Ang3 angles(0, 0, 0); Vec3 position(0, 0, 0); float scale = 1.0f; firstperson->GetAttribute("position", position); firstperson->GetAttribute("angles", angles); firstperson->GetAttribute("scale", scale); fpLocalTM = Matrix34(Matrix33::CreateRotationXYZ(DEG2RAD(angles))); fpLocalTM.Scale(Vec3(scale, scale, scale)); fpLocalTM.SetTranslation(position); fpGeometryName = modelName; } } }
IGL_INLINE void igl::sort_vectors_ccw( const Eigen::PlainObjectBase<DerivedS>& P, const Eigen::PlainObjectBase<DerivedS>& N, Eigen::PlainObjectBase<DerivedI> &order) { int half_degree = P.cols()/3; //local frame Eigen::Matrix<typename DerivedS::Scalar,1,3> e1 = P.head(3).normalized(); Eigen::Matrix<typename DerivedS::Scalar,1,3> e3 = N.normalized(); Eigen::Matrix<typename DerivedS::Scalar,1,3> e2 = e3.cross(e1); Eigen::Matrix<typename DerivedS::Scalar,3,3> F; F<<e1.transpose(),e2.transpose(),e3.transpose(); Eigen::Matrix<typename DerivedS::Scalar,Eigen::Dynamic,1> angles(half_degree,1); for (int i=0; i<half_degree; ++i) { Eigen::Matrix<typename DerivedS::Scalar,1,3> Pl = F.colPivHouseholderQr().solve(P.segment(i*3,3).transpose()).transpose(); // assert(fabs(Pl(2))/Pl.cwiseAbs().maxCoeff() <1e-5); angles[i] = atan2(Pl(1),Pl(0)); } igl::sort( angles, 1, true, angles, order); //make sure that the first element is always at the top while (order[0] != 0) { //do a circshift int temp = order[0]; for (int i =0; i< half_degree-1; ++i) order[i] = order[i+1]; order(half_degree-1) = temp; } }
static unsigned int DGetMinError(unsigned int yAxisNumber, Feature *yFeature){ /* Calculate angle of each point to the xAxis and sort them */ UPoints angles(n); for (unsigned int i = 0; i < n; i++){ angles[i] = UPoint((x[yAxisNumber][i] == 0 && curFeature[i] == 0) ? 0 : y[i] , atan2(x[yAxisNumber][i], curFeature[i])); } sort(angles.begin(), angles.end(), Compare); /* for (unsigned i = 0; i < n; i++){ cout << (angles[i].pattern > 0 ? 1 : angles[i].pattern < 0 ? 0 : 3); } cout << endl; */ /* Look for the optimal threshold */ int leftDiff = 0; unsigned int optThreshold = 0; int maxCorr = 0; double nextValue = angles[0].value; for (unsigned i = 0; i < n - 1; i++){ leftDiff += angles[i].pattern; if (angles[i + 1].value == nextValue){ continue; } nextValue = angles[i].value; int corr = max(numMore - leftDiff, numLess + leftDiff); //int corr = abs(leftDiff) + abs(difference - leftDiff); if (corr > maxCorr){ maxCorr = corr; optThreshold = i; } // cout << i << " " << corr << "; "; } // cout << endl; /* Determine the angle of the separating direction */ yFeature->angle = (angles[optThreshold].value + angles[optThreshold + 1].value) / 2. - PI2; yFeature->error = n - maxCorr; yFeature->number = yAxisNumber; return yFeature->error; }
int main(){ atoms(); velocities(); bonds(); angles(); dihedrals(); }
void CMultiMagicMissile::Create(Vec3f aePos, float afAlpha, float afBeta) { long lMax = 0; for(size_t i = 0; i < pTab.size(); i++) { Anglef angles(afAlpha, afBeta, 0.f); if(i > 0) { angles.setYaw(angles.getYaw() + frand2() * 4.0f); angles.setPitch(angles.getPitch() + frand2() * 6.0f); } pTab[i]->Create(aePos, angles); float fTime = ulDuration + frand2() * 1000.0f; long lTime = checked_range_cast<long>(fTime); lTime = std::max(1000L, lTime); lMax = std::max(lMax, lTime); CMagicMissile * pMM = (CMagicMissile *)pTab[i]; pMM->SetDuration(lTime); if(m_mrCheat) { pMM->SetColor(Color3f(0.9f, 0.2f, 0.5f)); } else { pMM->SetColor(Color3f(0.9f + rnd() * 0.1f, 0.9f + rnd() * 0.1f, 0.7f + rnd() * 0.3f)); } pTab[i]->lLightId = GetFreeDynLight(); if(lightHandleIsValid(pTab[i]->lLightId)) { EERIE_LIGHT * el = lightHandleGet(pTab[i]->lLightId); el->intensity = 0.7f + 2.3f; el->fallend = 190.f; el->fallstart = 80.f; if(m_mrCheat) { el->rgb.r = 1; el->rgb.g = 0.3f; el->rgb.b = 0.8f; } else { el->rgb.r = 0; el->rgb.g = 0; el->rgb.b = 1; } el->pos = pMM->eSrc; el->duration = 300; } } SetDuration(lMax + 1000); }
bool Manipulator::getSensedPosition(VectorXd &tcp) { /* Get current axis state */ VectorXd angles(ARMJOINTS); this->getSensedAxis(angles); /* Do forward transformation */ return this->solver->forwardTransformation(angles, tcp); }
gDial::gDial(int x, int y, int w, int h, const char *L) : Fl_Dial(x, y, w, h, L) { labelsize(11); labelcolor(COLOR_TEXT_0); align(FL_ALIGN_LEFT); type(FL_FILL_DIAL); angles(0, 360); color(COLOR_BG_0); // background selection_color(COLOR_BG_1); // selection }
template <typename PointInT, typename PointNT, typename PointOutT> bool pcl::BoundaryEstimation<PointInT, PointNT, PointOutT>::isBoundaryPoint ( const pcl::PointCloud<PointInT> &cloud, const PointInT &q_point, const std::vector<int> &indices, const Eigen::Vector4f &u, const Eigen::Vector4f &v, const float angle_threshold) { if (indices.size () < 3) return (false); if (!pcl_isfinite (q_point.x) || !pcl_isfinite (q_point.y) || !pcl_isfinite (q_point.z)) return (false); // Compute the angles between each neighboring point and the query point itself std::vector<float> angles (indices.size ()); float max_dif = FLT_MIN, dif; int cp = 0; for (size_t i = 0; i < indices.size (); ++i) { if (!pcl_isfinite (cloud.points[indices[i]].x) || !pcl_isfinite (cloud.points[indices[i]].y) || !pcl_isfinite (cloud.points[indices[i]].z)) continue; Eigen::Vector4f delta = cloud.points[indices[i]].getVector4fMap () - q_point.getVector4fMap (); if (delta == Eigen::Vector4f::Zero()) continue; angles[cp++] = atan2f (v.dot (delta), u.dot (delta)); // the angles are fine between -PI and PI too } if (cp == 0) return (false); angles.resize (cp); std::sort (angles.begin (), angles.end ()); // Compute the maximal angle difference between two consecutive angles for (size_t i = 0; i < angles.size () - 1; ++i) { dif = angles[i + 1] - angles[i]; if (max_dif < dif) max_dif = dif; } // Get the angle difference between the last and the first dif = 2 * static_cast<float> (M_PI) - angles[angles.size () - 1] + angles[0]; if (max_dif < dif) max_dif = dif; // Check results if (max_dif > angle_threshold) return (true); else return (false); }
gboolean EntityList::onSelection(GtkTreeSelection* selection, GtkTreeModel* model, GtkTreePath* path, gboolean path_currently_selected, gpointer data) { // Get a pointer to the class instance EntityList* self = reinterpret_cast<EntityList*>(data); if (self->_callbackActive) return TRUE; // avoid loops bool shouldFocus = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(self->_focusOnSelectedEntityToggle)) ? true : false; if (!shouldFocus) return TRUE; GtkTreeIter iter; gtk_tree_model_get_iter(model, &iter, path); // Load the instance pointer from the columns scene::INode* node = reinterpret_cast<scene::Node*>( gtkutil::TreeModel::getPointer(model, &iter, GraphTreeModel::COL_NODE_POINTER) ); Selectable* selectable = dynamic_cast<Selectable*>(node); if (selectable != NULL) { // We've found a selectable instance // Disable update to avoid loopbacks self->_callbackActive = true; // Select the instance selectable->setSelected(path_currently_selected == FALSE); const AABB& aabb = node->worldAABB(); Vector3 origin(aabb.origin); // Move the camera a bit off the AABB origin origin += Vector3(-50, 0, 50); // Rotate the camera a bit towards the "ground" Vector3 angles(0, 0, 0); angles[CAMERA_PITCH] = -30; GlobalCameraView().focusCamera(origin, angles); // Now reactivate the callbacks self->_callbackActive = false; return TRUE; // don't propagate } return FALSE; }
// // Draw the window // void Ex04opengl::paintGL() { // Wall time (seconds) float t = 0.001*time.elapsed(); if (move) zh = fmod(90*t,360); // Clear screen and Z-buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); // Set view glLoadIdentity(); if (fov) glTranslated(0,0,-2*dim); glRotated(ph,1,0,0); glRotated(th,0,1,0); // Translate intensity to color vectors float Ambient[] = {0.3,0.3,0.3,1.0}; float Diffuse[] = {0.8,0.8,0.8,1.0}; float Specular[] = {1.0,1.0,1.0,1.0}; float Position[] = {(float)(3*Cos(zh)),z0,(float)(3*Sin(zh)),1.0}; // Draw light position (no lighting yet) glColor3f(1,1,1); ball(Position[0],Position[1],Position[2] , 0.1); // OpenGL should normalize normal vectors glEnable(GL_NORMALIZE); // Enable lighting glEnable(GL_LIGHTING); // Enable light 0 glEnable(GL_LIGHT0); // Set ambient, diffuse, specular components and position of light 0 glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient); glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse); glLightfv(GL_LIGHT0,GL_SPECULAR,Specular); glLightfv(GL_LIGHT0,GL_POSITION,Position); // Apply shader if (mode) shader[mode].bind(); // Draw scene glPushMatrix(); if (obj) obj->display(); glPopMatrix(); // Release shader if (mode) shader[mode].release(); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); // Emit angles to display emit angles(QString::number(th)+","+QString::number(ph)); // Emit light angle emit light((int)zh); }
template<> Array<T> CubicHinges<TV2>::angles(RawArray<const Vector<int,3>> bends, RawArray<const TV2> X) { if (bends.size()) GEODE_ASSERT(X.size()>scalar_view(bends).max()); Array<T> angles(bends.size(),uninit); for (int b=0;b<bends.size();b++) { int i0,i1,i2;bends[b].get(i0,i1,i2); const TV x0 = X[i0], x1 = X[i1], x2 = X[i2]; angles[b] = angle_between(x1-x0,x2-x1); } return angles; }
void EV_FireGALIL( event_args_t *args ) { vec3_t ShellVelocity; vec3_t ShellOrigin; vec3_t vecSrc, vecAiming; int idx = args->entindex; Vector origin( args->origin ); Vector angles( args->iparam1 / 100.0f + args->angles[0], args->iparam2 / 100.0f + args->angles[1], args->angles[2] ); Vector velocity( args->velocity ); Vector forward, right, up; AngleVectors( angles, forward, right, up ); if ( EV_IsLocal( idx ) ) { ++g_iShotsFired; EV_MuzzleFlash(); gEngfuncs.pEventAPI->EV_WeaponAnimation(GALIL_SHOOT1 + Com_RandomLong(0,2), 2); if( !gHUD.cl_righthand->value ) { EV_GetDefaultShellInfo( args, origin, velocity, ShellVelocity, ShellOrigin, forward, right, up, 20.0, -8.0, -10.0, 0); } else { EV_GetDefaultShellInfo( args, origin, velocity, ShellVelocity, ShellOrigin, forward, right, up, 20.0, -8.0, 10.0, 0); } } else { EV_GetDefaultShellInfo( args, origin, velocity, ShellVelocity, ShellOrigin, forward, right, up, 20.0, -12.0, 4.0, 0); } EV_EjectBrass(ShellOrigin, ShellVelocity, angles[ YAW ], g_iRShell, TE_BOUNCE_SHELL); PLAY_EVENT_SOUND( SOUNDS_NAME[Com_RandomLong( 0, 1 )] ); EV_GetGunPosition( args, vecSrc, origin ); VectorCopy( forward, vecAiming ); Vector vSpread; vSpread.x = args->fparam1; vSpread.y = args->fparam2; EV_HLDM_FireBullets( idx, forward, right, up, 1, vecSrc, vecAiming, vSpread, 8192.0, BULLET_PLAYER_556MM, 2 ); }
bool QgsTriangle::isRight( double angleTolerance ) const { QVector<double> a = angles(); QVector<double>::iterator ita = a.begin(); while ( ita != a.end() ) { if ( qgsDoubleNear( *ita, M_PI_2, angleTolerance ) ) return true; ita++; } return false; }
//------------------------------------------------------------------------ void CRapid::UpdateRotation(float frameTime) { m_rotation_angle -= m_speed*frameTime*2.0f*3.141592f; Ang3 angles(0,m_rotation_angle,0); int slot=m_pWeapon->GetStats().fp? eIGS_FirstPerson: eIGS_ThirdPerson; Matrix34 tm = Matrix33::CreateRotationXYZ(angles); if (!m_pShared->rapidparams.barrel_attachment.empty()) m_pWeapon->SetCharacterAttachmentLocalTM(slot, m_pShared->rapidparams.barrel_attachment.c_str(), tm); if (!m_pShared->rapidparams.engine_attachment.empty()) m_pWeapon->SetCharacterAttachmentLocalTM(slot, m_pShared->rapidparams.engine_attachment.c_str(), tm); }
// // Draw the window // void Ex02opengl::paintGL() { // Clear screen and Z-buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); // Set view glLoadIdentity(); if (fov) glTranslated(0,0,-2*dim); glRotated(ph,1,0,0); glRotated(th,0,1,0); // Apply shader if (mode) { shader[mode].bind(); // Dimensions QVector3D dim(width(),height(),1); shader[mode].setUniformValue("dim",dim); } // Draw scene glPushMatrix(); glTranslated(x0*dim/100,y0*dim/100,z0*dim/100); if (obj) obj->display(); glPopMatrix(); // Release shader if (mode) shader[mode].release(); // Draw Axes glDisable(GL_DEPTH_TEST); glColor3f(1,1,1); glBegin(GL_LINES); glVertex3d(0,0,0); glVertex3d(1,0,0); glVertex3d(0,0,0); glVertex3d(0,1,0); glVertex3d(0,0,0); glVertex3d(0,0,1); glEnd(); // Label axes renderText(1,0,0,"X"); renderText(0,1,0,"Y"); renderText(0,0,1,"Z"); // Emit angles to display emit angles(QString::number(th)+","+QString::number(ph)); // Emit centers to display emit center(QString::number(x0)+","+QString::number(y0)+","+QString::number(z0)); }
//------------------------------------------------------------------------ bool CItem::SetGeometryFromParams(int slot, const IItemParamsNode *geometry) { FUNCTION_PROFILER(GetISystem(), PROFILE_GAME); const char *name = geometry->GetAttribute("name"); if(!name || !name[0]) { GameWarning("Missing geometry name for loading item '%s'!", GetEntity()->GetName()); return false; } Vec3 position(0,0,0); geometry->GetAttribute("position", position); Ang3 angles(0,0,0); geometry->GetAttribute("angles", angles); float scale=1.0f; geometry->GetAttribute("scale", scale); if(slot == eIGS_FirstPerson) { const char *hand = geometry->GetAttribute("hand"); int idx = 0; if(hand && hand[0]) { if(!stricmp(hand, "right")) idx = 1; else if(!stricmp(hand, "left")) idx = 2; else { GameWarning("Invalid hand '%s' loading item '%s'!", hand, GetEntity()->GetName()); return false; } } m_fpgeometry[idx].name=name; m_fpgeometry[idx].position=position; m_fpgeometry[idx].angles=DEG2RAD(angles); m_fpgeometry[idx].scale=scale; // marcio: first person geometry will be loaded upon selecting the weapon in first person //if (((idx<2) && (m_stats.hand == eIH_Right)) || ((idx==2) && (m_stats.hand == eIH_Left))) // SetGeometry(slot, name, position, DEG2RAD(angles), scale, false); } else SetGeometry(slot, name, position, DEG2RAD(angles), scale, false); return true; }
// ---------------------------------------------------------------------------- // void DefinitionWriter::visit( Channel* channel ) { TiXmlElement channel_element( "channel" ); add_attribute( channel_element, "index", (DWORD)channel->m_channel_offset ); add_attribute( channel_element, "type", (LPCSTR)channel->convertChannelTypeToText( channel->m_type ) ); add_attribute( channel_element, "color", channel->isColor() ); add_attribute( channel_element, "blackout", channel->canBlackout() ); if ( channel->m_default_value ) add_attribute( channel_element, "value", channel->m_default_value ); if ( channel->m_pixel_index ) add_attribute( channel_element, "pixel", channel->m_pixel_index ); if ( channel->m_home_value ) add_attribute( channel_element, "home_value", channel->m_home_value ); if ( channel->m_head_number ) add_attribute( channel_element, "head", channel->m_head_number ); // Add dimmer if ( channel->isDimmer() ) { TiXmlElement dimmer( "dimmer" ); add_attribute( dimmer, "strobe", channel->m_dimmer_can_strobe ); add_attribute( dimmer, "lowest_intensity", channel->m_lowest_intensity ); add_attribute( dimmer, "highest_intensity", channel->m_highest_intensity ); add_attribute( dimmer, "off_intensity", channel->m_off_intensity ); channel_element.InsertEndChild( dimmer ); } // Add strobe if ( channel->isStrobe() ) { TiXmlElement strobe( "strobe" ); add_attribute( strobe, "speed_slow", channel->m_strobe_slow ); add_attribute( strobe, "speed_fast", channel->m_strobe_fast ); add_attribute( strobe, "off", channel->m_strobe_off ); } add_text_element( channel_element, "name", channel->m_name ); if ( channel->m_ranges.size() > 0 && channel->m_type != CHNLT_PAN && channel->m_type != CHNLT_TILT ) { TiXmlElement ranges( "ranges" ); visit_array<ChannelValueRangeArray>( ranges, channel->m_ranges ); channel_element.InsertEndChild( ranges ); } if ( channel->m_angles.size() > 0 ) { TiXmlElement angles( "angles" ); visit_array<ChannelAngleArray>( angles, channel->m_angles ); channel_element.InsertEndChild( angles ); } getParent().InsertEndChild( channel_element ); }
Pose Robot::getPose() const { double x=0, y=0, z=0; std::vector<double> angles(NUM_ANGLES); // If we don't have any poses then return an empty pose. if (!poses_.size()) { return Pose(x, y, z, angles); } // If we only have one pose, then return it. if (poses_.size() == 1) { return poses_[0]; } // Return the current pose. // NOTE: poseIndex is double, NOT an int!!! Fractional values represent // interpolation between neighbouring poses. Eg: 2.5 would be halfway // between the 3rd and 4th pose. int wholeIndex = int(floor(poseIndex_)); double indexDiff = poseIndex_ - wholeIndex; Pose tempPose(poses_[wholeIndex].x_, poses_[wholeIndex].y_, poses_[wholeIndex].z_, angles); double angleDiff = 0; int nextIndex = 0; if (poseIndex_ < poses_.size() -1) { nextIndex = int(floor(poseIndex_)) + 1; } //Translation diff double diff = (poses_[nextIndex].x_ - poses_[int(floor(poseIndex_))].x_) * indexDiff; tempPose.x_ = tempPose.x_ + diff; diff = (poses_[nextIndex].y_ - poses_[int(floor(poseIndex_))].y_ ) * indexDiff; tempPose.y_ = tempPose.y_ + diff; diff = (poses_[nextIndex].z_ - poses_[int(floor(poseIndex_))].z_ ) * indexDiff; tempPose.z_ = tempPose.z_ + diff; //Angles diff for (int i = NUM_ANGLES; i >= 0; i--) { angleDiff = (poses_[nextIndex].angles_[i] - poses_[int(floor(poseIndex_))].angles_[i]) * indexDiff; tempPose.angles_[i] = poses_[int(floor(poseIndex_))].angles_[i] + angleDiff; } return tempPose; // @@@@@ Replace the above return statement with your own code to implement // @@@@@ linear interpolation between poses. }
template<> Array<T> CubicHinges<TV3>::angles(RawArray<const Vector<int,4>> bends, RawArray<const TV3> X) { if (bends.size()) GEODE_ASSERT(X.size()>scalar_view(bends).max()); Array<T> angles(bends.size(),uninit); for (int b=0;b<bends.size();b++) { int i0,i1,i2,i3;bends[b].get(i0,i1,i2,i3); const TV x0 = X[i0], x1 = X[i1], x2 = X[i2], x3 = X[i3], n0 = normal(x0,x2,x1), n1 = normal(x1,x2,x3); angles[b] = copysign(acos(clamp(dot(n0,n1),-1.,1.)),dot(n1-n0,x3-x0)); } return angles; }