Exemplo n.º 1
0
/**
 * Get the rotations that would make a (0,0,1) direction vector point in the same direction as this direction vector.
 * Useful for orienting vector towards a point.
 *
 * Returns a rotation vector containing the X (pitch) and Y (raw) rotations (in degrees) that when applied to a
 * +Z (e.g. 0, 0, 1) direction vector would make it point in the same direction as this vector. The Z (roll) rotation
 * is always 0, since two Euler rotations are sufficient to point in any given direction.
 *
 * Code ported from Irrlicht: http://irrlicht.sourceforge.net/
 */
kmVec3* kmVec3GetHorizontalAngle(kmVec3* pOut, const kmVec3 *pIn) {
   const kmScalar z1 = sqrt(pIn->x * pIn->x + pIn->z * pIn->z);

   pOut->y = kmRadiansToDegrees(atan2(pIn->x, pIn->z));
   if (pOut->y < 0)
      pOut->y += 360;
   if (pOut->y >= 360)
      pOut->y -= 360;

   pOut->x = kmRadiansToDegrees(atan2(z1, pIn->y)) - 90.0;
   if (pOut->x < 0)
      pOut->x += 360;
   if (pOut->x >= 360)
      pOut->x -= 360;

   return pOut;
}
Exemplo n.º 2
0
void cxViewReadAttr(cxReaderAttrInfo *info)
{
    cxObjectReadAttr(info);
    cxView this = info->object;
    //fixscale
    cxViewSetFixScale(this, cxXMLReadVec2fAttr(info, "cxView.fixScale", this->fixscale));
    //rect
    cxViewRootReadRectToView(info);
    //resize
    cxViewRootReadAutoResize(info);
    //cropping
    cxViewSetCropping(this,cxXMLReadBoolAttr(info, "cxView.cropping", this->isCropping));
    //top
    cxViewSetTop(this, cxXMLReadBoolAttr(info, "cxView.hideTop", this->hideTop));
    //anchor
    cxViewSetAnchor(this, cxXMLReadVec2fAttr(info, "cxView.anchor", this->anchor));
    //scale
    cxViewSetScale(this, cxXMLReadVec2fAttr(info, "cxView.scale", this->scale));
    //color
    cxColor4f color = cxXMLReadColor4fAttr(info, "cxView.color", this->color);
    cxViewSetColor(this, cxColor3fv(color.r, color.g, color.b));
    cxViewSetAlpha(this, cxXMLReadFloatAttr(info, "cxView.alpha", color.a));
    //visible
    cxViewSetVisible(this, cxXMLReadBoolAttr(info, "cxView.visible", this->isVisible));
    //debug border
    cxViewSetBorder(this, cxXMLReadBoolAttr(info, "cxView.border", this->isBorder));
    //rotate raxis
    cxViewSetRaxis(this, cxXMLReadVec3fAttr(info, "cxView.raxis", this->raxis));
    //rotate angle
    cxViewSetAngle(this, cxXMLReadFloatAttr(info, "cxView.angle", this->angle));
    //rotate degress
    cxViewSetDegrees(this, cxXMLReadFloatAttr(info, "cxView.degrees", kmRadiansToDegrees(this->angle)));
    //Chipmunk support
    cxViewCheckChipmunkSupport(info);
    //cxAtlas support
    this->supportAtlasSet = cxXMLReadBoolAttr(info, "cxAtlasSet.support", false);
    //view event
    cxXMLAppendEvent(info, this, cxView, onEnter);
    cxXMLAppendEvent(info, this, cxView, onExit);
    cxXMLAppendEvent(info, this, cxView, onUpdate);
    cxXMLAppendEvent(info, this, cxView, onResize);
    cxXMLAppendEvent(info, this, cxView, onLayout);
    cxXMLAppendEvent(info, this, cxView, onDirty);
}
Exemplo n.º 3
0
/**
 * 	Returns the angle in degrees between the two vectors
 */
kmScalar kmVec2DegreesBetween(const kmVec2* v1, const kmVec2* v2) {
	if(kmVec2AreEqual(v1, v2)) {
		return 0.0;
	}
	
	kmVec2 t1, t2;
	kmVec2Normalize(&t1, v1);
	kmVec2Normalize(&t2, v2);
	
	kmScalar cross = kmVec2Cross(&t1, &t2);
	kmScalar dot = kmVec2Dot(&t1, &t2);

	/*
	 * acos is only defined for -1 to 1. Outside the range we 
	 * get NaN even if that's just because of a floating point error
	 * so we clamp to the -1 - 1 range
	 */

	if(dot > 1.0) dot = 1.0;
	if(dot < -1.0) dot = -1.0;

	return kmRadiansToDegrees(atan2(cross, dot));
}
Exemplo n.º 4
0
Degrees to_degrees(const Radians& radians) {
    return Degrees(kmRadiansToDegrees(radians.value_));
}
Exemplo n.º 5
0
Degrees::Degrees(const Radians &rhs) {
    value_ = kmRadiansToDegrees(rhs.value_);
}