Example #1
0
void SkySim::initialize(v3d_t playerStartPosition) {

  // set up stars
  for (size_t i = 0; i < NUM_STARS; i++) {
    mStars[i].x = r_num (-10.0, 10.0);
    mStars[i].y = r_num (-10.0, 10.0);
    mStars[i].z = r_num (-10.0, 10.0);

    mStars[i] = v3d_scale (10000.0, v3d_normalize (mStars[i]));
  }

  // set up sun
  mCurrentSunPosition.x = (mSunPosition.x * cos (0.0)) - (mSunPosition.y * sin (0.0));
  mCurrentSunPosition.y = (mSunPosition.x * sin (0.0)) + (mSunPosition.y * cos (0.0));
  mCurrentSunPosition.z = mSunPosition.z;

//  assetManager.setDirectionalLightPositions (mCurrentSunPosition,
//    v3d_neg (mCurrentSunPosition));

  // now figure out the sky color and the world lighting
  setSkyColorAndWorldLighting ();

  // these can be combined eh?
  if (mCloudSim != NULL) {
    delete mCloudSim;
  }
  mCloudSim = new CloudSim();
  mCloudSim->newClouds (playerStartPosition);
}
Example #2
0
void rotationAboutAnAxis(GtkWidget *widget, gdouble phi, gint axe)
{
	GLdouble spin_quat[4] = {0,0,0,0};
	gdouble phiRad = phi/180*PI;
	if(axe<0 || axe>2) return;
	spin_quat[axe] = 1.0;

	v3d_scale(spin_quat,sin(phiRad/2));
	spin_quat[3] = cos(phiRad/2);

	add_quats(spin_quat, Quat, Quat);

}
Example #3
0
v3d_t LightSource::computeDirectionalLightIntensity (v3d_t normalVector, bool isTheSun) {
  double intensityScalar = v3d_dot (mDirection, normalVector);

  if (intensityScalar < 0.0) {
    intensityScalar = 0.0;
  }

  double overheadIntensity = v3d_dot (mDirection, v3d_v (0.0, 1.0, 0.0));

  if (overheadIntensity < 0.0) {
    intensityScalar += (overheadIntensity * 4.0);
  }
  else {
    intensityScalar += overheadIntensity;
  }

//  if (intensityScalar > 0.0 && intensityScalar < 0.5) {
//    intensityScalar = 0.5;
//  }


//  intensityScalar += (overheadIntensity + 0.3) * 0.5;

//  if (intensityScalar < 0.6) {
//    intensityScalar = 0.6;
//  }

/*
  if (isTheSun) {
    intensityScalar *= 0.2;
  }
  else {
    if (intensityScalar > 0.5) {
      intensityScalar = 0.5;
    }
  }
*/

  if (intensityScalar < 0.0) {
    intensityScalar = 0.0;
  }
  if (intensityScalar > 1.0) {
    intensityScalar = 1.0;
  }

  v3d_t color = v3d_scale (intensityScalar, mColor);

  return color;
}
Example #4
0
static void draw_bond_for_stick(int i,int j,GLdouble g, GabEditBondType bondType)
{
	
	int k;
	V4d Specular1 = {1.0f,1.0f,1.0f,1.0f};
	V4d Diffuse1  = {0.0f,0.0f,0.0f,1.0f};
	V4d Ambiant1  = {0.0f,0.0f,0.0f,1.0f};
	V4d Specular2 = {1.0f,1.0f,1.0f,1.0f};
	V4d Diffuse2  = {0.0f,0.0f,0.0f,1.0f};
	V4d Ambiant2  = {0.0f,0.0f,0.0f,1.0f};
	GLdouble p1;
	GLdouble p2;
	GLdouble aspect = g;
	
	  
	Specular1[0] = GeomOrb[i].Prop.color.red/(gdouble)65535;
	Specular1[1] = GeomOrb[i].Prop.color.green/(gdouble)65535;
	Specular1[2] = GeomOrb[i].Prop.color.blue/(gdouble)65535;

	Specular2[0] = GeomOrb[j].Prop.color.red/(gdouble)65535;
	Specular2[1] = GeomOrb[j].Prop.color.green/(gdouble)65535;
	Specular2[2] = GeomOrb[j].Prop.color.blue/(gdouble)65535;

	for(k=0;k<3;k++)
	{
		Diffuse1[k] = Specular1[k]*0.8;
		Diffuse2[k] = Specular2[k]*0.8;
	}
	for(k=0;k<3;k++)
	{
		Ambiant1[k] = Specular1[k]*0.5;
		Ambiant2[k] = Specular2[k]*0.5;
	}
	for(k=0;k<3;k++)
	{
		Ambiant1[k] = 0;
		Ambiant2[k] = 0;
	}
	for(k=0;k<3;k++)
	{
		Specular1[k] = 0.8;
		Specular2[k] = 0.8;
	}
	p1 = GeomOrb[i].Prop.covalentRadii+GeomOrb[i].Prop.radii;
	p2 = GeomOrb[j].Prop.covalentRadii+GeomOrb[j].Prop.radii;

	Cylinder_Draw_Color_Two(g,GeomOrb[i].C,GeomOrb[j].C,
				Specular1,Diffuse1,Ambiant1,
				Specular2,Diffuse2,Ambiant2,
				p1,p2);

	if(      bondType == GABEDIT_BONDTYPE_SINGLE ||
		( !ShowMultiBondsOrb && 
		 (bondType == GABEDIT_BONDTYPE_DOUBLE || bondType == GABEDIT_BONDTYPE_TRIPLE)
		 )
	    )
		Cylinder_Draw_Color_Two(g,GeomOrb[i].C,GeomOrb[j].C,
				Specular1,Diffuse1,Ambiant1,
				Specular2,Diffuse2,Ambiant2,
				p1,p2);
	else
	if(bondType == GABEDIT_BONDTYPE_DOUBLE && ShowMultiBondsOrb)
	{
	  	V3d vScal = {g/aspect*0.35,g/aspect*0.35,g/aspect*0.35};
		V3d C1;
		V3d C2;
		V3d cross;
		V3d sub;
		V3d CRing;
		getCentreRing(i,j, CRing);
		v3d_sub(CRing, GeomOrb[i].C, C1);
		v3d_sub(CRing, GeomOrb[j].C, C2);
		v3d_cross(C1, C2, cross);
		v3d_sub(GeomOrb[i].C, GeomOrb[j].C, sub);
		v3d_cross(cross, sub, vScal);
		if(v3d_dot(vScal,vScal)!=0)
		{
			v3d_normal(vScal);
			v3d_scale(vScal, g/aspect*0.35);
		}
		else
			 getvScaleBond(g/aspect*0.35*2, C1,C2, vScal);

		for(k=0;k<3;k++) C1[k] = GeomOrb[i].C[k];
		for(k=0;k<3;k++) C2[k] = GeomOrb[j].C[k];
		Cylinder_Draw_Color_Two(g,C1,C2, Specular1,Diffuse1,Ambiant1, Specular2,Diffuse2,Ambiant2, p1,p2);
		for(k=0;k<3;k++) C1[k] = GeomOrb[i].C[k]-vScal[k];
		for(k=0;k<3;k++) C2[k] = GeomOrb[j].C[k]-vScal[k];
		Cylinder_Draw_Color_Two(g/2,C1,C2, Specular1,Diffuse1,Ambiant1, Specular2,Diffuse2,Ambiant2, p1,p2);
	}
	else
	if(bondType == GABEDIT_BONDTYPE_TRIPLE && ShowMultiBondsOrb)
	{
	  	V3d vScal = {g/aspect*0.35,g/aspect*0.35,g/aspect*0.35};
		V3d C1;
		V3d C2;
		V3d cross;
		V3d sub;
		V3d CRing;
		getCentreRing(i,j, CRing);
		v3d_sub(CRing, GeomOrb[i].C, C1);
		v3d_sub(CRing, GeomOrb[j].C, C2);
		v3d_cross(C1, C2, cross);
		v3d_sub(GeomOrb[i].C, GeomOrb[j].C, sub);
		v3d_cross(cross, sub, vScal);
		if(v3d_dot(vScal,vScal)!=0)
		{
			v3d_normal(vScal);
			v3d_scale(vScal, g/aspect*0.35);
		}
		else
			 getvScaleBond(g/aspect*0.35*2, C1,C2, vScal);

		for(k=0;k<3;k++) C1[k] = GeomOrb[i].C[k]-vScal[k];
		for(k=0;k<3;k++) C2[k] = GeomOrb[j].C[k]-vScal[k];
		Cylinder_Draw_Color_Two(g/2,C1,C2, Specular1,Diffuse1,Ambiant1, Specular2,Diffuse2,Ambiant2, p1,p2);
		for(k=0;k<3;k++) C1[k] = GeomOrb[i].C[k];
		for(k=0;k<3;k++) C2[k] = GeomOrb[j].C[k];
		Cylinder_Draw_Color_Two(g,C1,C2, Specular1,Diffuse1,Ambiant1, Specular2,Diffuse2,Ambiant2, p1,p2);
		for(k=0;k<3;k++) C1[k] = GeomOrb[i].C[k]+vScal[k];
		for(k=0;k<3;k++) C2[k] = GeomOrb[j].C[k]+vScal[k];
		Cylinder_Draw_Color_Two(g/2,C1,C2, Specular1,Diffuse1,Ambiant1, Specular2,Diffuse2,Ambiant2, p1,p2);
	}

}
Example #5
0
void AiEntity::updateHopper() {
  v3d_t movementForce = v3d_zero();
  Physics& physics = *mGameModel->physics;
  double time = physics.getLastUpdateTime();

  if (mPhysicsEntity->health < 0.0) {
    return;
  }

  if (r_numi(0, 1085) == 3) {
    physics.addSoundEvent(SOUND_TIGER_ROAR, mPhysicsEntity->pos);
  }

  // keep it afloat in water even without a target
  if (mTargetPhysicsHandle == 0 && mPhysicsEntity->worldViscosity > 0.0) {
    physics.add_force(mPhysicsHandle, v3d_v(0.0, 4200.0, 0.0));
  }
  else if (physics.getIndexFromHandle(mTargetPhysicsHandle) >= 0) {
    PhysicsEntity *targetPhysicsEntity = physics.getEntityByHandle(mTargetPhysicsHandle);
    v3d_t targetPosition = targetPhysicsEntity->boundingBox.getCenterPosition();
    v3d_t vecToTarget = v3d_sub(targetPosition, mWorldPosition);

    if (mPhysicsEntity->worldViscosity > 0.0) {
      if (v3d_mag(vecToTarget) < mMinDistanceToPlayer) {
        vecToTarget = v3d_scale(1600.0 * (sin(time * 8.0) + 1.5), v3d_normalize(vecToTarget));

        movementForce = v3d_add(movementForce, vecToTarget);

        // give it a little more buoyancy
        if (targetPosition.y - mWorldPosition.y > 0.0) {
          physics.add_force(mPhysicsHandle, v3d_v(0.0, 2000.0, 0.0));
        }
      }
    }
    else if (mPhysicsEntity->on_ground) {
      vecToTarget.y = 0.0;

      if (v3d_mag(vecToTarget) < mMinDistanceToPlayer) {
        // big leap?
        if (r_numi(0, 60) == 3) {
          vecToTarget = v3d_scale(15000.0, v3d_normalize(vecToTarget));
          vecToTarget.y = 60000.0;
          movementForce = v3d_add(movementForce, vecToTarget);
        }
        else {
          vecToTarget = v3d_scale(2000.0, v3d_normalize(vecToTarget));
          //vecToTarget.y = r_num(8000.0, 10000.0);
          movementForce = v3d_add(movementForce, vecToTarget);
        }
      }
    }
    else {
      vecToTarget.y = 0.0;

      if (v3d_mag(vecToTarget) < mMinDistanceToPlayer) {
        vecToTarget = v3d_scale(5.0, v3d_normalize(vecToTarget));
  //      vecToPlayer.y = 20.0;
        movementForce = v3d_add(movementForce, vecToTarget);
      }
    }

    physics.add_force(mPhysicsHandle, movementForce);
  }
}
Example #6
0
void AiEntity::updateBalloon() {
  v3d_t movementForce = v3d_zero();
  Physics& physics = *mGameModel->physics;
  double time = physics.getLastUpdateTime();

  if (mPhysicsEntity->worldViscosity > 0.0) {
    physics.add_force(mPhysicsHandle, v3d_v(0.0, 120.0, 0.0));
  }

  if (physics.getIndexFromHandle(mTargetPhysicsHandle) >= 0) {
    // we can't fly if we're on the ground!
    if (mPhysicsEntity->on_ground) {
//      movementForce = v3d_v(0.0, 8000.0, 0.0);
      physics.add_force(mPhysicsHandle, v3d_v(0.0, 8000.0, 0.0));
    }

    PhysicsEntity* targetPhysicsEntity = physics.getEntityByHandle(mTargetPhysicsHandle);
    if (targetPhysicsEntity == NULL) {
      printf("AiEntity::updateBalloon() - target is NULL\n");
      return;
    }

    v3d_t targetPosition = targetPhysicsEntity->boundingBox.getCenterPosition();

    // let's keep this thing afloat
    double desiredHeight;
    if (targetPhysicsEntity->aiType == AITYPE_HOPPER ||
      targetPhysicsEntity->aiType == AITYPE_SHOOTER ||
      targetPhysicsEntity->aiType == AITYPE_PLAYER)
    {
      double sin2 = (2.0 * sin(time));
      desiredHeight = targetPosition.y + 14.0 + sin2;
      double height2 = mGameModel->location->getWorldMap()->mPeriodics->getTerrainHeight(mWorldPosition.x, mWorldPosition.z) + 10.0 + sin2;
      if (height2 > desiredHeight) {
        desiredHeight = height2;
      }
    }
    else {
      // this is so that when floaters fight they don't just keep flying higher
      desiredHeight = mGameModel->location->getWorldMap()->mPeriodics->getTerrainHeight(mWorldPosition.x, mWorldPosition.z) + 10.0 + (2.0 * sin(time));
    }

    double delta = mWorldPosition.y - desiredHeight;

    if (delta > 0.0) {
  //    delta += 0.2 * mPhysicsEntity.vel.y;
      delta = 0.0;
    }
    else if (delta < 0.0) {
      delta += 0.2 * mPhysicsEntity->vel.y;
    }

    double forceMagnitude = 5.0 * (delta * delta); //; - physicsEntity.vel.y;

    if (forceMagnitude > 200.0) {
      forceMagnitude = 200.0;
    }

    if (delta > 0.0) {
      movementForce = v3d_v(0.0, -0.5 * forceMagnitude, 0.0);
    }
    else {
      movementForce = v3d_v(0.0, forceMagnitude, 0.0);
    }

    // try to get to the target

    v3d_t vecToTarget = v3d_sub(targetPosition, mWorldPosition);
    vecToTarget.y = 0.0;

    v3d_t velNoY = mPhysicsEntity->vel;
    velNoY.y = 0.0;

    // FIXME: there needs to be a check here to see if the AI
    // is going the 'long way' to turn towards it's target
    double angle1 = atan2(vecToTarget.x, vecToTarget.z);
    double angle2 = atan2(velNoY.x, velNoY.z);
    double angle = angle1 - angle2;

    if (abs(angle) > 0.1) {
      if (abs(angle) > M_PI) {
        angle = -angle;
      }

      angle = absConstrain(angle, 0.01);

      v3d_t rot = v3d_rotateY(mPhysicsEntity->vel, angle);
      mPhysicsEntity->vel.x = rot.x;
      mPhysicsEntity->vel.z = rot.z;
    }

    if (v3d_mag(vecToTarget) < mMinDistanceToPlayer) {
      vecToTarget = v3d_scale(15.0, v3d_normalize(vecToTarget));
      movementForce = v3d_add(movementForce, vecToTarget);
    }

//    physics.add_force (mPhysicsHandle, movementForce);
//    mPhysicsEntity->force = v3d_add(mPhysicsEntity->force, movementForce);

    mPhysicsEntity->force.x += movementForce.x;
    mPhysicsEntity->force.y += movementForce.y;
    mPhysicsEntity->force.z += movementForce.z;
  }
}
Example #7
0
void v3d_normal(V3d v)
{
    v3d_scale(v,1.0/v3d_length(v));
}
Example #8
0
bool WorldMap::rayCastSolidBlock(const v3d_t &a, const v3d_t &b, v3di_t &hitPosition, int &face) const {
  v3d_t diff = v3d_sub(b, a);

  double magnitude = v3d_mag(diff);
  double step = 1.0 / (10.0 * magnitude);

  v3di_t blockPosition;
  v3d_t pos;
  v3d_t lastPos = a;

static v3d_t faceAdd[6] = {
    {{ 0.0, 0.0, 0.0 }},    // BLOCK_SIDE_LEF
    {{ 1.0, 0.0, 0.0 }},    // BLOCK_SIDE_RIG
    {{ 0.0, 1.0, 0.0 }},    // BLOCK_SIDE_TOP
    {{ 0.0, 0.0, 0.0 }},    // BLOCK_SIDE_BOT
    {{ 0.0, 0.0, 1.0 }},    // BLOCK_SIDE_FRO
    {{ 0.0, 0.0, 0.0 }}     // BLOCK_SIDE_BAC
  };

  for (double t = step; t <= 1.0; t += step) {
    pos = v3d_add (a, v3d_scale (t, diff));

    // TODO: check if this is the same v3di_t that was checked last frame
    blockPosition = v3di_v (pos);
    block_t *block = getBlock(blockPosition);

    // special case for plants...
    if (block != NULL && gBlockData.get(block->type)->solidityType == BLOCK_SOLIDITY_TYPE_PLANT) {
      hitPosition = blockPosition;
      face = 0;
      return true;
    }

    if (isSolidBlock(blockPosition)) {
      // the return value gets set
      hitPosition = blockPosition;

      // figure out which face was intersected first

      double faceHitResults[NUM_BLOCK_SIDES];
      double faceHitTimes[NUM_BLOCK_SIDES];

      for (int s = 0; s < NUM_BLOCK_SIDES; s++) {
        Plane3d plane;

        v3d_t point = v3d_add(v3d_v(blockPosition), faceAdd[s]);
        v3d_t normal = {
          gCubeFaceNormalLookup[s][0],
          gCubeFaceNormalLookup[s][1],
          gCubeFaceNormalLookup[s][2] };

        plane.setFromPointAndNormal(point, normal);

        faceHitResults[s] = plane.doesLineSegmentIntersect(lastPos, pos, faceHitTimes[s]);
      }

      double soonestHit = 1000.0;    // super high value

      // this section sets the 'face' variable to the nearest face
      for (int s = 0; s < NUM_BLOCK_SIDES; s++) {
        if (faceHitResults[s]) {
          if (faceHitTimes[s] > 0.0 && faceHitTimes[s] < soonestHit) {
            soonestHit = faceHitTimes[s];
            face = s;
          }
        }
      }

      return true;
    }

    lastPos = pos;
  }

  return false;
}