Beispiel #1
0
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()));
}
Beispiel #2
0
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);
}
Beispiel #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);
}
Beispiel #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);
}
Beispiel #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;
}
Beispiel #6
0
void R3Matrix:: 
Rotate(const R3Vector& radians)
{
  XRotate(radians.X());
  YRotate(radians.Y());
  ZRotate(radians.Z());
}
Beispiel #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;
}
Beispiel #8
0
R3Point 
operator-(const R3Point& point, const R3Vector& vector)
{
    return R3Point(point.X() - vector.X(), 
		   point.Y() - vector.Y(), 
		   point.Z() - vector.Z());
}
Beispiel #9
0
void R3Matrix::Scale(const R3Vector& scale)
{
    // Scale matrix
    XScale(scale.X());
    YScale(scale.Y());
    ZScale(scale.Z());
}
Beispiel #10
0
void R3Matrix::Translate(const R3Vector& offset)
{
    // Translate matrix
    XTranslate(offset.X());
    YTranslate(offset.Y());
    ZTranslate(offset.Z());
}
Beispiel #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());
}
Beispiel #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;
    }
    */
    
    
} }
Beispiel #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);
}
Beispiel #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;
}
Beispiel #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
}
Beispiel #16
0
void Rails::Update(double dt)
{
    time -= dt;
    if (time < 0) {
        int i = -1;
        int j = -1;
        time += 1.0/MOVE_SPEED*(double)GetWidth()/TERRAIN_DPS;//*GetWidth()/(double)TERRAIN_SIZE;//TERRAIN_SIZE/(double)TERRAIN_DPS;//*coeff;//(double)GetWidth()*coeff;

        float greatest = 0;
        R2Point previousLocation = oldLocation;
        R2Point firstLocation = currentLocation;
        R2Point secondLocation = currentLocation;
        for (int k = 0; k < 5; k++) {
            float greatest = 0;
            for (i = -1; i <= 1; i++) {
                for (j = -1; j <= 1; j++) {
                    if (i == 0 && j == 0)
                        continue;
                    if (params.railMap->Pixel(currentLocation.X()+i,currentLocation.Y()+j)[0] > greatest) {
                        R2Point tempLocation = R2Point(currentLocation.X()+i,currentLocation.Y()+j);
                        if (tempLocation.X() != oldLocation.X() || tempLocation.Y() != oldLocation.Y()) {
                            if (tempLocation.X() != oldoldLocation.X() || tempLocation.Y() != oldoldLocation.Y()) {
                                greatest = params.railMap->Pixel(currentLocation.X()+i,currentLocation.Y()+j)[0];
                                nextLocation = tempLocation;
                            }
                        }
                    }
                }
            } 

            if (k==0)
                secondLocation = nextLocation;
            oldoldLocation = oldLocation;
            oldLocation = currentLocation;
            currentLocation = nextLocation;

        }
        for (i = -1; i <= 1; i++) {
            for (j = -1; j <= 1; j++) {
                if (i == 0 && j == 0)
                    continue;
                if (params.railMap->Pixel(currentLocation.X()+i,currentLocation.Y()+j)[2] > .5) {
                    globals.levelStatus = 1;
                    globals.gsmgr->Stop();
                }
            }
        } 



        R3Vector v = R3Vector(-(currentLocation.X()-firstLocation.X()), 0, currentLocation.Y()-firstLocation.Y());
        targetDirection = acos(-R3zaxis_vector.Dot(v)/v.Length());
        targetDirection = targetDirection - (int)(targetDirection/6.28);
        if (v.X() < 0) {
            targetDirection = 6.28-targetDirection;
        }
        oldoldLocation = previousLocation;
        oldLocation = firstLocation;
        currentLocation = secondLocation;

    }
    //double coeff = (sqrt(2) - 1)*abs((firstLocation.X()-currentLocation.X())*(currentLocation.Y()-firstLocation.Y())) + 1;
    //printf("coeff %f\n", coeff);
    float closeness = 0;
    if (targetDirection < 0)
        closeness = (-currentDirection + targetDirection);
    else
        closeness = (-currentDirection + targetDirection);
    currentDirection += ROLL_SPEED*dt * closeness;//abs(closeness)*closeness;
    if (abs(currentDirection - targetDirection) > .05) {
        /*
           if (currentDirection < targetDirection)
           currentDirection += ROLL_SPEED*dt;
           if (currentDirection > targetDirection)
           currentDirection -= ROLL_SPEED*dt;
           */
    }
    //currentDirection = targetDirection;//abs(closeness)*closeness;
    globals.player->SetDirection(currentDirection);
}