bool MovementAdapterWorkerDiscrete::injectMouseMove(const MouseMotion& motion, bool& freezeMouse) { //this will move the entity instead of the mouse Vector<3> direction; direction.zero(); direction.x() = -motion.xRelativeMovement; direction.y() = motion.yRelativeMovement; direction = direction * mMovementSpeed; //hard coded to allow the shift button to increase the speed // if (Input::getSingleton().isKeyDown(SDLK_RSHIFT) || Input::getSingleton().isKeyDown(SDLK_LSHIFT)) { // direction = direction * 5; // } Quaternion orientation = Convert::toWF(getCamera().getOrientation()); //We need to constraint the orientation to only around the z axis. WFMath::Vector<3> rotator(1.0, 0.0, 0.0); rotator.rotate(orientation); WFMath::Quaternion adjustedOrientation; adjustedOrientation.fromRotMatrix(WFMath::RotMatrix<3>().rotationZ(atan2(rotator.y(), rotator.x()))); orientation = adjustedOrientation; //move it relative to the camera direction = direction.rotate(orientation); getBridge()->move(direction);//move the entity a fixed distance for each mouse movement. //we don't want to move the cursor freezeMouse = true; return false; }
void Doom3Group::rotate(const Quaternion& rotation) { if (!isModel()) { ChildRotator rotator(rotation); _owner.traverse(rotator); } else { m_rotation.rotate(rotation); } }
//--------------------------------------------------------------------------------------- // # Skookum: Rotation@String() String // # Author(s): Markus Breyer static void mthd_String(SkInvokedMethod * scope_p, SkInstance ** result_pp) { // Do nothing if result not desired if (result_pp) { const FQuat & rotation = scope_p->this_as<SkRotation>(); FRotator rotator(rotation); AString str(128u, "(yaw=%g, pitch=%g, roll=%g)", double(rotator.Yaw), double(rotator.Pitch), double(rotator.Roll)); *result_pp = SkString::new_instance(str); } }
bool Flip::toolOperations() { DImg::FLIP flip = (DImg::FLIP)(settings()[QLatin1String("Flip")].toInt()); if (JPEGUtils::isJpegImage(inputUrl().toLocalFile()) && image().isNull()) { JPEGUtils::JpegRotator rotator(inputUrl().toLocalFile()); rotator.setDestinationFile(outputUrl().toLocalFile()); switch (flip) { case DImg::HORIZONTAL: return rotator.exifTransform(MetaEngineRotation::FlipHorizontal); break; case DImg::VERTICAL: return rotator.exifTransform(MetaEngineRotation::FlipVertical); break; default: qCDebug(DIGIKAM_DPLUGIN_BQM_LOG) << "Unknown flip action"; return false; break; } } if (!loadToDImg()) { return false; } DImgBuiltinFilter filter; switch (flip) { case DImg::HORIZONTAL: filter = DImgBuiltinFilter(DImgBuiltinFilter::FlipHorizontally); break; case DImg::VERTICAL: filter = DImgBuiltinFilter(DImgBuiltinFilter::FlipVertically); break; } applyFilter(&filter); return (savefromDImg()); }
void EntityMaker::createEntityOfType(Eris::TypeInfo* typeinfo, const std::string& parentEntityId, const std::string& name) { Atlas::Objects::Operation::Create c; c->setFrom(mAvatar.getId()); //if the avatar is a "creator", i.e. and admin, we will set the TO property //this will bypass all of the server's filtering, allowing us to create any entity and have it have a working mind too if (mAvatar.getIsAdmin()) { c->setTo(mAvatar.getEntityId()); } Atlas::Message::MapType msg; msg["loc"] = parentEntityId; WFMath::Point<3> pos = WFMath::Point<3>::ZERO(); WFMath::Quaternion orientation = WFMath::Quaternion::Identity(); //Only place it if we're creating the new entity in the same location as the avatar if (parentEntityId == mAvatar.getEntity()->getLocation()->getId()) { //Place the new entity two meters in front of the avatar. WFMath::Vector<3> vector(0, 0, 2); //We need to constraint the orientation to only around the y axis. WFMath::Vector<3> rotator(0.0, 0.0, 1.0f); rotator.rotate(mAvatar.getEntity()->getOrientation()); auto atan = std::atan2(rotator.x(), rotator.z()); orientation.rotation(1, atan); pos = mAvatar.getEntity()->getPosition() + (vector.rotate(orientation)); } msg["pos"] = pos.toAtlas(); msg["orientation"] = orientation.toAtlas(); if (!name.empty()) { msg["name"] = name; } msg["parent"] = typeinfo->getName(); c->setArgsAsList(Atlas::Message::ListType(1, msg)); mConnection.send(c); std::stringstream ss; ss << pos; S_LOG_INFO("Trying to create entity of type " << typeinfo->getName() << " at position " << ss.str()); }
// Luna task 748T void ConvertPathToFrenets (Spline3D *pSpline, Matrix3 & relativeTransform, Tab<Matrix3> & tFrenets, int numSegs, bool align, float rotateAroundZ) { // Given a path, a sequence of points in 3-space, create transforms // for putting a cross-section around each of those points, loft-style. // bezShape is provided by user, tFrenets contains output, numSegs is one less than the number of transforms requested. // Strategy: The Z-axis is mapped along the path, and the X and Y axes // are chosen in a well-defined manner to get an orthonormal basis. int i; if (numSegs < 1) return; tFrenets.SetCount (numSegs+1); int numIntervals = pSpline->Closed() ? numSegs+1 : numSegs; float denominator = float(numIntervals); Point3 xDir, yDir, zDir, location, tangent, axis; float position, sine, cosine, theta; Matrix3 rotation; // Find initial x,y directions: location = relativeTransform * pSpline->InterpCurve3D (0.0f); tangent = relativeTransform.VectorTransform (pSpline->TangentCurve3D (0.0f)); Point3 lastTangent = tangent; Matrix3 inverseBasisOfSpline(1); if (align) { theBasisFinder.BasisFromZDir (tangent, xDir, yDir); if (rotateAroundZ) { Matrix3 rotator(1); rotator.SetRotate (AngAxis (tangent, rotateAroundZ)); xDir = xDir * rotator; yDir = yDir * rotator; } Matrix3 basisOfSpline(1); basisOfSpline.SetRow (0, xDir); basisOfSpline.SetRow (1, yDir); basisOfSpline.SetRow (2, tangent); basisOfSpline.SetTrans (location); inverseBasisOfSpline = Inverse (basisOfSpline); lastTangent = Point3(0,0,1); } else { inverseBasisOfSpline.SetRow (3, -location); } // Make relative transform take the spline from its own object space to our object space, // and from there into the space defined by its origin and initial direction: relativeTransform = relativeTransform * inverseBasisOfSpline; // (Note left-to-right evaluation order: Given matrices A,B, point x, x(AB) = (xA)B // The first transform is necessarily the identity: tFrenets[0].IdentityMatrix (); // Set up xDir, yDir, zDir to match our first-point basis: xDir = Point3 (1,0,0); yDir = Point3 (0,1,0); zDir = Point3 (0,0,1); for (i=1; i<=numIntervals; i++) { position = float(i) / denominator; location = relativeTransform * pSpline->InterpCurve3D (position); tangent = relativeTransform.VectorTransform (pSpline->TangentCurve3D (position)); // This is the procedure we follow at each step in the path: find the // orthonormal basis with the right orientation, then compose with // the translation putting the origin at the path-point. // As we proceed along the path, we apply minimal rotations to // our original basis to keep the Z-axis tangent to the curve. // The X and Y axes follow in a natural manner. // xDir, yDir, zDir still have their values from last time... // Create a rotation matrix which maps the last tangent onto the current tangent: axis = lastTangent ^ tangent; // gives axis, scaled by sine of angle. sine = FLength(axis); // positive - keeps angle value in (0,PI) range. cosine = DotProd (lastTangent, tangent); // Gives cosine of angle. theta = atan2f (sine, cosine); rotation.SetRotate (AngAxis (Normalize(axis), theta)); xDir = Normalize (rotation * xDir); yDir = Normalize (rotation * yDir); zDir = Normalize (rotation * zDir); lastTangent = tangent; if (i<=numSegs) { tFrenets[i].IdentityMatrix (); tFrenets[i].SetRow (0, xDir); tFrenets[i].SetRow (1, yDir); tFrenets[i].SetRow (2, zDir); tFrenets[i].SetTrans (location); } } /* following code not needed for now - treating all splines as open. if (!pSpline->Closed ()) return; // If we have a closed loop, our procedure may result in X,Y vectors // that are twisted severely between the first and last point. // Here we correct for that by pre-transforming each frenet transform // by a small rotation around the Z-axis. (The last pass through the above // loop should give the final twist: the initial and final Z-axis directions // are the same, and the difference between the initial and final X-axis // directions is the total twist along the spline.) // Now we measure the difference between our original and final x-vectors: axis = originalXDir ^ xDir; sine = FLength (axis); cosine = DotProd (originalXDir, xDir); theta = atan2f (sine, cosine); for (i=1; i<=numSegs; i++) { rotation.SetRotate (AngAxis (Normalize(axis), -theta/denominator)); tFrenets[i] = rotation * tFrenets[i]; } */ }