示例#1
0
文件: R3Cont.C 项目: acplus/peptalk
RNBoolean R3Contains(const R3Vector& vector1, const R3Vector& vector2)
{
    // Return whether vector1 and vector2 are equal within tolerance
    return (RNIsEqual(vector1.X(), vector2.X()) &&
            RNIsEqual(vector1.Y(), vector2.Y()) &&
            RNIsEqual(vector1.Z(), vector2.Z()));
}
示例#2
0
文件: R3Cont.C 项目: acplus/peptalk
RNBoolean R3Contains(const R3Sphere& sphere, const R3Point& point)
{
    // Return whether sphere contains point
    RNScalar radius_squared = sphere.Radius() * sphere.Radius();
    R3Vector v = sphere.Center() - point;
    RNScalar distance_squared = v.X() * v.X() + v.Y() * v.Y() + v.Z() * v.Z();
    return RNIsLessOrEqual(distance_squared, radius_squared);
}
示例#3
0
R3Vector operator*(const R3Matrix& a, const R3Vector& v)
{
    // Multiply matrix by vector
    double x = a.m[0][0] * v.X() + a.m[0][1] * v.Y() + a.m[0][2] * v.Z();
    double y = a.m[1][0] * v.X() + a.m[1][1] * v.Y() + a.m[1][2] * v.Z();
    double z = a.m[2][0] * v.X() + a.m[2][1] * v.Y() + a.m[2][2] * v.Z();
    return R3Vector(x, y, z);
}
示例#4
0
R3Vector
operator*(const R4Matrix& a, const R3Vector& v)
{
    // Multiply matrix by vector
    RNCoord x = a.m[0][0] * v.X() + a.m[0][1] * v.Y() + a.m[0][2] * v.Z();
    RNCoord y = a.m[1][0] * v.X() + a.m[1][1] * v.Y() + a.m[1][2] * v.Z();
    RNCoord z = a.m[2][0] * v.X() + a.m[2][1] * v.Y() + a.m[2][2] * v.Z();
    return R3Vector(x, y, z);
}
示例#5
0
RNBoolean R3Parallel(const R3Vector& vector1, const R3Vector& vector2)
{
    // Return whether two vectors are coincident (or anti-coincident)
    if ((RNIsEqual(vector1.X(), vector2.X())) &&
        (RNIsEqual(vector1.Y(), vector2.Y())) && 
        (RNIsEqual(vector1.Z(), vector2.Z()))) return TRUE;
    if ((RNIsEqual(vector1.X(), -vector2.X())) &&
        (RNIsEqual(vector1.Y(), -vector2.Y())) && 
        (RNIsEqual(vector1.Z(), -vector2.Z()))) return TRUE;
    return FALSE;
}
示例#6
0
void R3Matrix:: 
Rotate(const R3Vector& radians)
{
  XRotate(radians.X());
  YRotate(radians.Y());
  ZRotate(radians.Z());
}
示例#7
0
int Bubble::Collides(R3Mesh* mesh, R3Vector offset) {
  R3Box box = mesh -> bbox;

  R3Vector SepAxis = pos - (box.Centroid() + offset);

  double dist = SepAxis.Length();
  SepAxis.Normalize();

  double x = SepAxis.X();
  double y = SepAxis.Y();
  double z = SepAxis.Z();

  if (x >= y && x >= z && x != 0)
    SepAxis /= x;
  else if (y >= x && y >= z != 0)
    SepAxis /= y;
  else if (z != 0)
    SepAxis /= z;

  double x_len = box.XLength();
  double y_len = box.YLength();
  double z_len = box.ZLength();

  //effective radius
  SepAxis.SetX(x * x_len/2.0);
  SepAxis.SetY(y * y_len/2.0);
  SepAxis.SetZ(z * z_len/2.0);

  if (dist <= (size + SepAxis.Length()))
    return 1;	
  return 0;
}
示例#8
0
R3Point 
operator-(const R3Point& point, const R3Vector& vector)
{
    return R3Point(point.X() - vector.X(), 
		   point.Y() - vector.Y(), 
		   point.Z() - vector.Z());
}
示例#9
0
void R3Matrix::Scale(const R3Vector& scale)
{
    // Scale matrix
    XScale(scale.X());
    YScale(scale.Y());
    ZScale(scale.Z());
}
示例#10
0
void R3Matrix::Translate(const R3Vector& offset)
{
    // Translate matrix
    XTranslate(offset.X());
    YTranslate(offset.Y());
    ZTranslate(offset.Z());
}
示例#11
0
void R3Point:: 
Rotate(const R3Vector& radians)
{
    // Rotate first around X, then around Y, and finally around Z
    ZRotate(radians.Z());
    YRotate(radians.Y());
    XRotate(radians.X());
}
示例#12
0
void Bearpaw::
updatePosition(double delta_time, R3Point playerPos) { //, double bound, R3Scene *scene, vector<Bearpaw>& Bearpaw_list, vector<Hunter>& hunter_list, R3Box bearBBox)
{
    fprintf(stderr, "center at {%f, %f, %f}\n",shape.mesh->Center().X(), shape.mesh->Center().Y(), shape.mesh->Center().Z());
    position = playerPos + playeroffset;
    
    R3Vector toNew = position - shape.mesh->Center();
    fprintf(stderr, "moving by {%f, %f, %f}\n",toNew.X(), toNew.Y(), toNew.Z());
	shape.mesh->Translate(toNew.X(), toNew.Y(), toNew.Z());
	bbox = shape.mesh->bbox;
    
    /*
    R3Vector 
    fromPlayer.SetY(0);

    fromPlayer.Normalize();
    
    position += fromPlayer*delta_time*speed;
    
    // update the y-position
    R3Vector grav = R3Vector(0,-15,0);
    R3Vector f_grav = mass * grav;
    R3Vector accel = f_grav / mass;
    position.Translate(delta_time * velocity);
    velocity += delta_time * accel;
    if (position.Y() <= 4.0) { // currently a magic number
        position.SetY(4.0);
        velocity += R3Vector(0,10,0);
    }
    

    if (shape.type == R3_MESH_SHAPE) {    // only going to use a mesh for the bear paw
        R3Vector toNew = position - shape.mesh->Center();
		shape.mesh->Translate(toNew.X(), toNew.Y(), toNew.Z());
		bbox = shape.mesh->bbox;
    }
    */
    
    
} }
示例#13
0
R3Matrix R3Matrix::Rotation(const R3Vector& axis, double radians)
{
    // rotate matrix for arbitrary axis counterclockwise
    // From Graphics Gems I, p. 466
    double x = axis.X();
    double y = axis.Y();
    double z = axis.Z();
    double c = cos(radians);
    double s = sin(radians);
    double t = 1.0 - c;
    return R3Matrix(t*x*x + c, t*x*y - s*z, t*x*z + s*y, 0.0,
            t*x*y + s*z, t*y*y + c, t*y*z - s*x, 0.0,
            t*x*z - s*y, t*y*z + s*x, t*z*z + c, 0.0,
            0.0, 0.0, 0.0, 1.0);
}
示例#14
0
void R4Matrix:: 
Rotate(const R3Vector& axis, RNAngle radians)
{
    // rotate matrix for arbitrary axis counterclockwise
    // From Graphics Gems I, p. 466
    RNCoord x = axis.X();
    RNCoord y = axis.Y();
    RNCoord z = axis.Z();
    RNScalar c = cos(radians);
    RNScalar s = sin(radians);
    RNScalar t = 1.0 - c;
    R4Matrix rotation(
        t*x*x + c, t*x*y - s*z, t*x*z + s*y, 0.0,
        t*x*y + s*z, t*y*y + c, t*y*z - s*x, 0.0,
        t*x*z - s*y, t*y*z + s*x, t*z*z + c, 0.0,
        0.0, 0.0, 0.0, 1.0);
    *this *= rotation;
}
示例#15
0
void R4Matrix:: 
Rotate(const R3Vector& radians)
{
#if 1
    // Rotate first around X, then around Y, and finally around Z
    ZRotate(radians.Z());
    YRotate(radians.Y());
    XRotate(radians.X());
#else
    // This is faster way to do same thing (not tested)
    R4Matrix rotation(
      cos(radians.Y())*cos(radians.Z()),  
      sin(radians.X())*sin(radians.Y())*cos(radians.Z()) - cos(radians.X())*sin(radians.Z()), 
      cos(radians.X())*sin(radians.Y())*cos(radians.Z()) + sin(radians.X())*sin(radians.Z()), 0,
      cos(radians.Y())*sin(radians.Z()),
      sin(radians.X())*sin(radians.Y())*sin(radians.Z()) + cos(radians.X())*cos(radians.Z()),
      cos(radians.X())*sin(radians.Y())*sin(radians.Z()) - sin(radians.X())*cos(radians.Z()), 0,
      -sin(radians.Y()), 
      cos(radians.Y())*sin(radians.X()),
      cos(radians.X())*cos(radians.Y()), 0,
      0, 0, 0, 1);
    *this = rotation * (*this);
#endif
}