本文整理汇总了C++中direction函数的典型用法代码示例。如果您正苦于以下问题:C++ direction函数的具体用法?C++ direction怎么用?C++ direction使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了direction函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RectConeIntersect
bool RectConeIntersect(const Rect * rect, const Cone * cone)
{
Circle circle(cone->GetVertex(), cone->GetHeight());
if (Intersect(rect, &circle) == true)
{
Point2D corners[4] =
{
Point2D(rect->GetLeft(), rect->GetTop()),
Point2D(rect->GetLeft(), rect->GetBottom()),
Point2D(rect->GetRight(), rect->GetBottom()),
Point2D(rect->GetRight(), rect->GetTop()),
};
if (rect->ContainsPoint(cone->GetVertex()) == true)
{
return true;
}
for (uint8 i = 0; i < 4; i++)
{
if (cone->ContainsPoint(corners[i]) == true)
{
return true;
}
}
Vector3D direction(cone->GetVertex(), cone->GetVertex() + cone->GetDirection());
Float angle = direction.GetZeroAngleD();
Float angle1 = angle + cone->GetAngle();
Float angle2 = angle - cone->GetAngle();
Float height = cone->GetHeight();
Point3D vertex = cone->GetVertex();
LineSegment line1(vertex, Point3D(vertex.GetX() + (CosD(angle1) * height), vertex.GetY() + (SinD(angle1) * height), 0));
LineSegment line2(vertex, Point3D(vertex.GetX() + (CosD(angle2) * height), vertex.GetY() + (SinD(angle2) * height), 0));
return ((Intersect(rect, &line1) == true) || (Intersect(rect, &line2) == true));
}
return false;
}
示例2: MMatrix
MMatrix sgHair_controlJoint::getAngleWeightedMatrix( const MMatrix& targetMtx, double weight )
{
MMatrix mtx;
if( m_bStaticRotation )
{
mtx = MMatrix() * ( weight-1 ) + targetMtx * weight;
cleanMatrix( mtx );
}
else
{
MVector vUpDefault( 0, 1, 0 );
MVector vCrossDefault( 0,0,1 );
MVector vUpInput( targetMtx(1,0), targetMtx(1,1), targetMtx(1,2) );
double angleUp = vUpInput.angle( vUpDefault ) * weight;
if( vUpInput.x == 0 && vUpInput.z == 0 ) vUpInput.x = 1;
MVector direction( vUpInput.x, 0, vUpInput.z );
direction.normalize();
MVector vUp( sin( angleUp ) * direction.x, cos( angleUp ), sin( angleUp ) * direction.z );
double dot = vUp * MVector( 0.0, 0.0, 1.0 );
MVector vCross( 0.0, -dot, (dot+1) );
MVector vAim = vUp ^ vCross;
vAim.normalize();
vUp.normalize();
vCross = vAim ^ vUp;
mtx( 0, 0 ) = vAim.x;
mtx( 0, 1 ) = vAim.y;
mtx( 0, 2 ) = vAim.z;
mtx( 1, 0 ) = vUp.x;
mtx( 1, 1 ) = vUp.y;
mtx( 1, 2 ) = vUp.z;
mtx( 2, 0 ) = vCross.x;
mtx( 2, 1 ) = vCross.y;
mtx( 2, 2 ) = vCross.z;
}
return mtx;
}
示例3: direction
bool shape::intersects(shape const& shape) const {
vector direction(shape.centroid() - centroid());
std::vector<vector> simplex;
simplex.push_back(vertices_[support(direction)] - shape.vertices()[shape.support(-direction)]);
direction = -direction;
for(;;) {
vector const a(vertices_[support(direction)] - shape.vertices()[shape.support(-direction)]);
if(a.dot(direction) <= 0.0f)
return false;
simplex.push_back(a);
vector const ao(-a);
if(simplex.size() == 3) {
vector const b(simplex[1]);
vector const c(simplex[0]);
vector const ab(b - a);
vector const ac(c - a);
vector const ab_triple(vector::triple_product_left(ac, ab, ab));
if(ab_triple.dot(ao) >= 0.0f) {
simplex.erase(simplex.begin());
direction = ab_triple;
} else {
vector const ac_triple(vector::triple_product_left(ab, ac, ac));
if(ac_triple.dot(ao) >= 0.0f) {
simplex.erase(simplex.begin() + 1);
direction = ac_triple;
} else
return true;
}
} else {
vector const b(simplex[0]);
vector const ab(b - a);
direction = vector::triple_product_left(ab, ao, ab);
if(!direction)
direction = ab.left();
}
}
}
示例4: vsCollisionObject
void
vpDrawable::ConvertToPhysics_Rigid()
{
m_objectCount = 1;
m_object = new vsCollisionObject *[1];
bool isStatic = false;
if ( m_drawMode == DrawMode_Static )
isStatic = true;
m_object[0] = new vsCollisionObject( ColFlag_Player, ColFlag_All, isStatic );
// for each line of our optimised model, add a box to our collision object!
for ( int i = 0; i < m_optimisedIndexCount-1; i++ )
{
const vsVector2D &start = m_samplePos[m_optimisedIndex[i]];
const vsVector2D &end = m_samplePos[m_optimisedIndex[i+1]];
vsVector2D direction(end.x-start.x,end.y-start.y);
vsAngle ang = vsAngle::FromForwardVector(direction);
float length = direction.Length();
if ( length > 0.f )
{
float density = 1.0f;
float width = 0.15f;
if ( m_drawMode == DrawMode_Static )
density = 0.f;
vsVector2D extent( width, length );
vsVector2D midpoint = 0.5f * (start + end);
m_object[0]->AddBox( extent, midpoint, ang, density );
}
}
m_object[0]->SetCollisionsActive(true);
m_object[0]->SetUserData(this);
m_object[0]->SetResponder(this);
}
示例5: update
void update(entityx::EntityManager &es, entityx::EventManager &events, double dt)
{
entityx::ComponentHandle<Moveable> moveable;
entityx::ComponentHandle<Position> position;
entityx::ComponentHandle<Player> player;
for(entityx::Entity entity : es.entities_with_components(player))
{
float x = 0.0f;
float y = 0.0f;
const Uint8 *state = SDL_GetKeyboardState(NULL);
if(state[SDL_SCANCODE_W])
{
y-=1.0f;
}
if(state[SDL_SCANCODE_A])
{
x-=1.0f;
}
if(state[SDL_SCANCODE_S])
{
y+=1.0f;
}
if(state[SDL_SCANCODE_D])
{
x+=1.0f;
}
if(state[SDL_SCANCODE_SPACE])
{
events.emit<PlayerInstructionLight>(entity);
}
if(x != 0.0f || y != 0.0f)
{
glm::vec2 direction(x,y);
direction = glm::normalize(direction);// *(float) dt;
events.emit<PlayerInstructionEvent>(direction,entity);
}
}
}
示例6: printf
int MovingObject::status()
{
printf("Method: %c\n", _method);
printf("First: %d - Last: %d\n", _first(), _last);
printf("RealQueueSize: %d\n", _realQueueSize);
printf("Filled: %s\n", _filled?"true":"false");
printf("Valorized: %s\n", _valorized()?"true":"false");
int i, count;
if (_valorized()) {
for(i=_first(), count=0; _filled?count<_realQueueSize:i<=_last; i++, count++) {
i=i%_realQueueSize;
printf(" Values[%d]: %f, %f\n", i, _lastValues_X[i], _lastValues_Y[i]);
}
}
printf("Distance: %f\n", coveredDistance());
printf("Speed: %f\n", speed());
printf("Direction: %f\n", direction()*180/PI);
printf("---\n");
return 0;
}
示例7: drawArrow
void drawArrow(Vector2f const& from, Vector2f const& to, Color3f const& color, float width) {
Vector2f direction((to-from).normalize()*width*0.5f);
Vector2f normal(direction.y_, -direction.x_);
glBlendFunc(GL_ONE, GL_ONE);
glLineWidth(width);
glBegin(GL_TRIANGLES);
(color*0.5f).gl3f();
glVertex2f(from.x_,from.y_);
color.gl3f();
glVertex2f(to.x_-normal.x_,to.y_-normal.y_);
glVertex2f(to.x_+normal.x_,to.y_+normal.y_);
glVertex2f(to.x_+direction.x_*3.f,to.y_+direction.y_*3.f);
glVertex2f(to.x_+normal.x_*2.f,to.y_+normal.y_*2.f);
glVertex2f(to.x_-normal.x_*2.f,to.y_-normal.y_*2.f);
glEnd();
}
示例8: Q_UNUSED
void RGBMatrix::preRun(MasterTimer* timer)
{
Q_UNUSED(timer);
FixtureGroup* grp = doc()->fixtureGroup(fixtureGroup());
{
QMutexLocker algorithmLocker(&m_algorithmMutex);
if (grp != NULL && m_algorithm != NULL)
{
m_direction = direction();
Q_ASSERT(m_fader == NULL);
m_fader = new GenericFader(doc());
m_fader->adjustIntensity(getAttributeValue(Intensity));
if (m_direction == Forward)
{
m_step = 0;
m_stepColor = m_startColor.rgb();
}
else
{
m_step = m_algorithm->rgbMapStepCount(grp->size()) - 1;
if (m_endColor.isValid())
{
m_stepColor = m_endColor.rgb();
}
else
{
m_stepColor = m_startColor.rgb();
}
}
calculateColorDelta();
}
}
m_roundTime->start();
Function::preRun(timer);
}
示例9: tprintf
// Refits the baseline to a constrained angle, using the stored block
// skew if good enough, otherwise the supplied default skew.
void BaselineBlock::ParallelizeBaselines(double default_block_skew) {
if (non_text_block_) return;
if (!good_skew_angle_) skew_angle_ = default_block_skew;
if (debug_level_ > 0)
tprintf("Adjusting block to skew angle %g\n", skew_angle_);
FCOORD direction(cos(skew_angle_), sin(skew_angle_));
for (int r = 0; r < rows_.size(); ++r) {
BaselineRow* row = rows_[r];
row->AdjustBaselineToParallel(debug_level_, direction);
if (debug_level_ > 1)
row->Print();
}
if (rows_.size() < 3 || !ComputeLineSpacing())
return;
// Enforce the line spacing model on all lines that don't yet have a good
// baseline.
// Start by finding the row that is best fitted to the model.
int best_row = 0;
double best_error = SpacingModelError(rows_[0]->PerpDisp(direction),
line_spacing_, line_offset_);
for (int r = 1; r < rows_.size(); ++r) {
double error = SpacingModelError(rows_[r]->PerpDisp(direction),
line_spacing_, line_offset_);
if (error < best_error) {
best_error = error;
best_row = r;
}
}
// Starting at the best fitting row, work outwards, syncing the offset.
double offset = line_offset_;
for (int r = best_row + 1; r < rows_.size(); ++r) {
offset = rows_[r]->AdjustBaselineToGrid(debug_level_, direction,
line_spacing_, offset);
}
offset = line_offset_;
for (int r = best_row - 1; r >= 0; --r) {
offset = rows_[r]->AdjustBaselineToGrid(debug_level_, direction,
line_spacing_, offset);
}
}
示例10: direction
void LevelFactory::LoadDirectionalLights(XMLReader& aReader, tinyxml2::XMLElement* aLevelElement)
{
for (tinyxml2::XMLElement* entityElement = aReader.FindFirstChild(aLevelElement, "directionallight"); entityElement != nullptr;
entityElement = aReader.FindNextElement(entityElement, "directionallight"))
{
tinyxml2::XMLElement* directionalElement = aReader.ForceFindFirstChild(entityElement, "rotation");
Prism::DirectionalLight* newDirLight = new Prism::DirectionalLight();
CU::Vector3<float> lightDirection;
aReader.ForceReadAttribute(directionalElement, "X", lightDirection.x);
aReader.ForceReadAttribute(directionalElement, "Y", lightDirection.y);
aReader.ForceReadAttribute(directionalElement, "Z", lightDirection.z);
CU::Matrix44<float> orientation;
CU::GetOrientation(orientation, lightDirection);
CU::Vector3<float> direction(0.f, 0.f, 1.f);
direction = direction * orientation;
newDirLight->SetDir(direction);
//newDirLight->SetOrientation(orientation);
//newDirLight->SetDir(lightDirection);
directionalElement = aReader.ForceFindFirstChild(entityElement, "color");
CU::Vector4<float> lightColor;
aReader.ForceReadAttribute(directionalElement, "R", lightColor.myR);
aReader.ForceReadAttribute(directionalElement, "G", lightColor.myG);
aReader.ForceReadAttribute(directionalElement, "B", lightColor.myB);
aReader.ForceReadAttribute(directionalElement, "A", lightColor.myA);
newDirLight->SetColor(lightColor);
myDirectionalLights.Add(newDirLight);
}
}
示例11: algorithmLocker
void RGBMatrix::preRun(MasterTimer* timer)
{
{
QMutexLocker algorithmLocker(&m_algorithmMutex);
m_group = doc()->fixtureGroup(m_fixtureGroupID);
if (m_group == NULL)
{
// No fixture group to control
stop(FunctionParent::master());
return;
}
if (m_algorithm != NULL)
{
Q_ASSERT(m_fader == NULL);
m_fader = new GenericFader(doc());
m_fader->adjustIntensity(getAttributeValue(Intensity));
m_fader->setBlendMode(blendMode());
// Copy direction from parent class direction
m_stepHandler->initializeDirection(direction(), m_startColor, m_endColor, m_stepsCount);
if (m_algorithm->type() == RGBAlgorithm::Script)
{
RGBScript *script = static_cast<RGBScript*> (m_algorithm);
QHashIterator<QString, QString> it(m_properties);
while(it.hasNext())
{
it.next();
script->setProperty(it.key(), it.value());
}
}
}
}
m_roundTime->restart();
Function::preRun(timer);
}
示例12: waveNumber
void stokesFifthProperties::set( Ostream& os)
{
scalar k = waveNumber();
// Write the beginning of the sub-dictionary
writeBeginning( os );
// Write the already given parameters
writeGiven( os, "waveType" );
writeGiven( os, "height");
writeGiven( os, "period" );
writeGiven( os, "depth" );
writeGiven( os, "stokesDrift");
writeGiven( os, "direction" );
if (dict_.found( "Tsoft" ))
{
writeGiven( os, "Tsoft");
}
writeGiven( os, "phi");
if (write_)
{
vector direction( vector(dict_.lookup("direction")));
direction /= Foam::mag(direction);
direction *= k;
writeDerived(os, "waveNumber", direction);
writeDerived(os, "omega", omega_);
}
// Write the relaxation zone
writeRelaxationZone( os );
// Write the closing bracket
writeEnding( os );
}
示例13: glPushName
void CylinderMy::draw_with_name(unsigned int i) const {
glPushName(i);
{
GLUquadricObj* qobj = gluNewQuadric();
glPushMatrix();
glTranslatef(base_center_.x(), base_center_.y(), base_center_.z());
double angle = 0.0;
double x = 1.0;
double y = 0.0;
double z = 0.0;
//--- Compute orientation of normal
// TODO: Comparing doubles with == or != is not safe
Vector3d dir = direction();
if((dir.x() == 0.0f) && (dir.y() == 0.0f)) {
if(dir.z() > 0)
angle = 0.0f;
else
angle = 180.0f;
}
else {
Vector3d k(0.0f, 0.0f, 1.0f);
Vector3d tmp = CGAL::cross_product(dir, k);
angle = std::acos(dir * k);
angle = -180.0f * angle / M_PI;
x = tmp[0];
y = tmp[1];
z = tmp[2];
}
glRotatef(angle, x, y, z);
gluCylinder(qobj, radius_, radius_, height(), 30, 1);
glPopMatrix();
gluDeleteQuadric(qobj);
}
glPopName();
}
示例14: GetAbsOrigin
CBaseEntity *CDecal::GetDecalEntityAndPosition( Vector *pPosition, bool bStatic )
{
CBaseEntity *pEntity = NULL;
if ( !m_entityName )
{
trace_t trace;
Vector start = GetAbsOrigin();
Vector direction(1,1,1);
if ( GetAbsAngles() == vec3_angle )
{
start -= direction * 5;
}
else
{
GetVectors( &direction, NULL, NULL );
}
Vector end = start + direction * 10;
if ( bStatic )
{
CTraceFilterValidForDecal traceFilter( this, COLLISION_GROUP_NONE );
UTIL_TraceLine( start, end, MASK_SOLID, &traceFilter, &trace );
}
else
{
UTIL_TraceLine( start, end, MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &trace );
}
if ( trace.DidHitNonWorldEntity() )
{
*pPosition = trace.endpos;
return trace.m_pEnt;
}
}
else
{
pEntity = gEntList.FindEntityByName( NULL, m_entityName );
}
*pPosition = GetAbsOrigin();
return pEntity;
}
示例15: ASSERT
TextRun SVGInlineTextBox::constructTextRun(RenderStyle* style, const SVGTextFragment& fragment) const
{
ASSERT(style);
ASSERT(textRenderer());
RenderText* text = textRenderer();
ASSERT(text);
// FIXME(crbug.com/264211): This should not be necessary but can occur if we
// layout during layout. Remove this when 264211 is fixed.
RELEASE_ASSERT(!text->needsLayout());
TextRun run(static_cast<const LChar*>(0) // characters, will be set below if non-zero.
, 0 // length, will be set below if non-zero.
, 0 // xPos, only relevant with allowTabs=true
, 0 // padding, only relevant for justified text, not relevant for SVG
, TextRun::AllowTrailingExpansion
, direction()
, dirOverride() || style->rtlOrdering() == VisualOrder /* directionalOverride */);
if (fragment.length) {
if (text->is8Bit())
run.setText(text->characters8() + fragment.characterOffset, fragment.length);
else
run.setText(text->characters16() + fragment.characterOffset, fragment.length);
}
if (textRunNeedsRenderingContext(style->font()))
run.setRenderingContext(SVGTextRunRenderingContext::create(text));
run.disableRoundingHacks();
// We handle letter & word spacing ourselves.
run.disableSpacing();
// Propagate the maximum length of the characters buffer to the TextRun, even when we're only processing a substring.
run.setCharactersLength(text->textLength() - fragment.characterOffset);
ASSERT(run.charactersLength() >= run.length());
return run;
}