Ejemplo n.º 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);
}
Ejemplo n.º 2
0
void World::growSpiralTree (v3di_t position) {
  position.y++;

  block_t *pBlock = mWorldMap->getBlock (position);
  if (pBlock != NULL &&
    pBlock->type != BLOCK_TYPE_AIR)
  {
    return;
  }

  int blockType = BLOCK_TYPE_ALIEN_SKIN3;

  v3d_t top;

  top.x = position.x;
  top.z = position.z;
  double bottom = getTerrainHeight (static_cast<int>(floor (top.x)),
    static_cast<int>(floor (top.z))) - 4.0;

  v3d_t pos;

  double percent;
  double angle;
  int numSteps = 50;

  double sphereRadiusStart = 1.5;
  double sphereRadiusEnd = 1.0;
  double sphereRadius;


  double radius = r_num (1.0, 2.0);
  double totalRotation = r_num (2.0, 4.0) * 1.5;
  double height = r_num (10.0, 20.0);

  top.y = bottom + height;

  BYTE uniqueLighting = LIGHT_LEVEL_MIN; //static_cast<GLfloat>(r_num (-0.3, 0.0));

  for (int step = 0; step < numSteps; step++) {
    percent = static_cast<double> (step) / static_cast<double>(numSteps - 1);
    angle = percent * totalRotation;

    pos.x = top.x + radius * cos (angle);
    pos.y = lerp (bottom, top.y, percent);
    pos.z = top.z + radius * sin (angle);

    sphereRadius = lerp (sphereRadiusStart, sphereRadiusEnd, percent);

    mWorldMap->fillSphere (pos, sphereRadius, blockType, uniqueLighting);
  }
}
Ejemplo n.º 3
0
void Galaxy::randomize(size_t numSystems) {
  for (size_t i = 0; i < numSystems; i++) {
    StarSystem *starSystem = new StarSystem();
    if (starSystem == NULL) {
      printf("Galaxy::Galaxy(): out of memory\n");
      return;
    }

    starSystem->mHandle = mNextHandle++;
    starSystem->mPosition.x = r_num(0.0, GALACTIC_WIDTH);
    starSystem->mPosition.y = r_num(0.0, GALACTIC_HEIGHT);

    starSystem->randomize();
    mNextHandle += starSystem->mPlanets.size();

    mStarSystems.push_back(starSystem);
  }
}
Ejemplo n.º 4
0
void Location::init()
{
   haveflag=0;
   newrental=0;
   heat=0;
   heat_protection=0.0;
   closed=0;
   mapped=0;
   highsecurity=0;
   mapseed=seed;r_num();
   changes.clear();
   compound_walls=0;
   compound_stores=0;
   front_business=-1;
}
Ejemplo n.º 5
0
void DungeonUtil::drawCrookedLine(double x1, double y1, double x2, double y2, int subdivisons, float maxDisplacement, float brushSize, const SelectiveDungeonTile& tile) {
  // we'll use a midpoint displacement algorithm here
  // we need to allow variance in the brushSize probably
  // WARNING: precision might be too bad like this


  if (subdivisons > 0) {
    // find the perpendicular to the line
    v2d_t offset = v2d_normalize(v2d_v(x2 - x1, y2 - y1));
    // not done yet...
    double temp = offset.vec[0];
    offset.vec[0] = offset.vec[1];
    offset.vec[1] = -temp;

    // scale it
    offset = v2d_scale(r_num(-maxDisplacement, maxDisplacement), offset);

    double offsetMidpointX = avg(x1, x2) + offset.x;
    double offsetMidpointY = avg(y1, y2) + offset.y;

    maxDisplacement *= DISPLACEMENT_SCALE;

    drawCrookedLine(x1, y1, offsetMidpointX, offsetMidpointY, subdivisons - 1, maxDisplacement, brushSize, tile);
    drawCrookedLine(offsetMidpointX, offsetMidpointY, x2, y2, subdivisons - 1, maxDisplacement, brushSize, tile);
  }
  else {
    // WARNING: is this really an acceptable way to draw this line?
//    float lineLength = dist(x1, y1, x2, y2);

    double lineLength = v2d_dist(v2d_v(x1, y1), v2d_v (x2, y2));

    int steps = MACRO_MAX(round_int(lineLength / (brushSize * 0.5f)), 1);

//    drawLine(round_int(x1), round_int(y1), round_int(x2), round_int(y2), brushSize, steps, tile);
    drawLine(x1, y1, x2, y2, brushSize, steps, tile);
  }
}
Ejemplo n.º 6
0
void AiEntity::aquireTarget() {
  double minDistance = 100000.0;
  int minHandle = -1;

  Physics& physics = *mGameModel->physics;
  vector<AiEntity*>& aiEntities = *mGameModel->aiManager->getEntities();
  WorldMap& worldMap = *mGameModel->location->getWorldMap();

  // try to find target
  for (size_t j = 0; j < aiEntities.size (); j++) {
    // ignore self and dead things
    if (!aiEntities[j]->mActive || aiEntities[j]->mType == mType || aiEntities[j]->mHandle == mHandle) {
      continue;
    }

    if (DONT_ATTACK_PLAYER && aiEntities[j]->mType == AITYPE_PLAYER) continue;
    // ignore player if same species...
    // FIXME: hard-wired
    if (aiEntities[j]->mType == AITYPE_PLAYER && mType == PLAYER_SPECIES) continue;

    size_t jPhysicsHandle = aiEntities[j]->mPhysicsHandle;
    // don't target if dead
    mTargetPhysicsEntity = physics.getEntityByHandle(jPhysicsHandle);
    if (mTargetPhysicsEntity == NULL) continue;
    if (mTargetPhysicsEntity->health <= 0.0) continue;

    double jDistance = v3d_dist(mWorldPosition, physics.getCenter(jPhysicsHandle));

    if (jDistance <= 35.0 && jDistance < minDistance) {
      // check for line of sight
      if (worldMap.lineOfSight(mWorldPosition, physics.getCenter(jPhysicsHandle))) {
        minHandle = static_cast<int>(jPhysicsHandle);
        minDistance = jDistance;
      }
    }
  }

  if (minHandle > 0) {
    mTargetPhysicsHandle = minHandle;
    mTargetPhysicsEntity = physics.getEntityByHandle(mTargetPhysicsHandle);
    return;
  }
  else {
    mTargetPhysicsHandle = 0;
    mTargetPhysicsEntity = NULL;
  }

  // perhaps a stroll...
  if (mTargetPhysicsHandle == 0 && r_numi(0, 5) == 2) {
    PhysicsEntity* playerPhysicsEntity = physics.getEntityByHandle(physics.getPlayerHandle());
    v3d_t baitPosition;
    if(playerPhysicsEntity != NULL) {
      // hehe let's sneak up on the player!
      baitPosition = v3d_add(playerPhysicsEntity->pos, v3d_v(r_num(-40.0, 40.0), 10.0, r_num(-40.0, 40.0)));
    }
    else {
      baitPosition = v3d_add(mWorldPosition, v3d_v(r_num(-25.0, 25.0), 10.0, r_num(-25.0, 25.0)));
    }

    PhysicsEntity *baitPhysicsEntity = physics.createEntity(OBJTYPE_TIGER_BAIT, baitPosition, true);
    if (baitPhysicsEntity != NULL) {
      physics.setHealth(baitPhysicsEntity->handle, 1.0);
      mTargetPhysicsHandle = baitPhysicsEntity->handle;
      mTargetPhysicsEntity = baitPhysicsEntity;
    }
    return;
  }
}
Ejemplo n.º 7
0
void FeatureGenerator::growSpiralGarden(
  v2di_t cornerIndex,
  int sideX,
  int sideZ,
  World &world)
{


  int worldX = cornerIndex.x * WORLD_CHUNK_SIDE;
  int worldZ = cornerIndex.y * WORLD_CHUNK_SIDE;

  int sideLengthX = sideX * WORLD_CHUNK_SIDE;
  int sideLengthZ = sideZ * WORLD_CHUNK_SIDE;

  height_info_t heightInfo = FeatureUtil::getHeightInfo(worldX, worldZ, sideLengthX, sideLengthZ, world);

  int blockType;
  int numSpirals;
  int blockRNum = r_numi(0, 4);
  switch (blockRNum) {
  case 0:
    blockType = BLOCK_TYPE_DARK_PURPLE;
    numSpirals = r_numi(20, 35);
    break;

  case 1:
    blockType = BLOCK_TYPE_FUSCHIA;
    numSpirals = r_numi(3, 15);
    break;

  case 2:
    blockType = BLOCK_TYPE_NAVY_BLUE;
    numSpirals = r_numi(50, 100);
    break;

  case 3:
  default:
    blockType = BLOCK_TYPE_BRICK_RED;
    numSpirals = r_numi(7, 15);
    break;
  }

  WorldMap &worldMap = *world.getWorldMap();
  for (int i = 0; i < numSpirals; i++) {
    v3d_t top;

    double height;

    top.x = worldX + r_num(10.0, static_cast<double>(sideLengthX)-10.0);
    top.z = worldZ + r_num(10.0, static_cast<double>(sideLengthZ)-10.0);
    double bottom = world.getTerrainHeight(static_cast<int>(top.x), static_cast<int>(top.z));

    v3d_t pos;

    double percent;
    double angle;
    int numSteps = 100;
    double totalRotation;
    double radius;

    double sphereRadiusStart = 2.1;
    double sphereRadiusEnd = 1.1;
    double sphereRadius;


    switch (blockType) {
    case BLOCK_TYPE_DARK_PURPLE:
      radius = r_num(2.0, 4.0);
      totalRotation = r_num(2.0, 4.0) * 2.0;
      height = r_num(15.0, 30.0);
      break;

    case BLOCK_TYPE_SLUDGE:
      radius = r_num(4.0, 7.0);
      totalRotation = r_num(2.0, 4.0) * 6.28;
      height = r_num(35.0, 75.0);
      sphereRadiusStart = 2.5;
      sphereRadiusEnd = 4.0;
      break;

    case BLOCK_TYPE_NAVY_BLUE:
      radius = r_num(2.0, 3.0);
      totalRotation = r_num(2.0, 4.0) * 2.0;
      height = r_num(10.0, 20.0);
      sphereRadiusStart = 2.5;
      sphereRadiusEnd = 1.0;
      break;

    case BLOCK_TYPE_BRICK_RED:
    default:
      radius = r_num(3.0, 6.0);
      totalRotation = r_num(2.0, 4.0) * 6.28;
      height = r_num(10.0, 25.0);
      break;
    }

    top.y = bottom + height;

    for (int step = 0; step < numSteps; step++) {
      percent = static_cast<double> (step) / static_cast<double>(numSteps - 1);
      angle = percent * totalRotation;

      pos.x = top.x + radius * cos(angle);
      pos.y = lerp(bottom, top.y, percent);
      pos.z = top.z + radius * sin(angle);

      sphereRadius = lerp(sphereRadiusStart, sphereRadiusEnd, percent);

      worldMap.fillSphere(pos, sphereRadius, blockType, LIGHT_LEVEL_SOLID);
    }

  }
}
Ejemplo n.º 8
0
void FeatureGenerator::drillCavern(
  v2di_t cornerIndex,
  int sideX,
  int sideZ,
  World &world)
{
  int worldX = cornerIndex.x * WORLD_CHUNK_SIDE;
  int worldZ = cornerIndex.y * WORLD_CHUNK_SIDE;

  int sideLengthX = sideX * WORLD_CHUNK_SIDE;
  int sideLengthZ = sideZ * WORLD_CHUNK_SIDE;

  //  height_info_t heightInfo = getHeightInfo (worldX, worldZ, sideLengthX, sideLengthZ, worldMap);

  double halfSideX = (double)sideLengthX / 2;
  double halfSideZ = (double)sideLengthZ / 2;

  v3d_t centerPos = {
    (double)worldX + halfSideX,
    0.0,
    (double)worldZ + halfSideZ
  };

  v3d_t pos;

  for (int j = 0; j < 6; j++) {
    pos.x = centerPos.x + r_num(-halfSideX * 0.9, halfSideX * 0.9);
    pos.z = centerPos.z + r_num(-halfSideZ * 0.9, halfSideZ * 0.9);
    pos.y = (double)(world.getTerrainHeight((int)pos.x, (int)pos.z));

    double angle = r_num(0.0, MY_2PI);

    v3d_t vel = {
      cos(angle),
      0.5,
      sin(angle)
    };

    double radius = r_num(1.0, 4.0);

    WorldMap &worldMap = *world.getWorldMap();
    for (int i = 0; i < 75; i++) {
      //      worldMap.clearSphere (pos, 4.0);
      worldMap.fillSphere(pos, radius, BLOCK_TYPE_DARK_PURPLE, LIGHT_LEVEL_SOLID);

      pos = v3d_add(pos, vel);

      radius += r_num(-0.1, 0.1);
      if (radius < 1.0) {
        radius = 1.0;
      }
      if (radius > 4.0) {
        radius = 4.0;
      }

      vel.x += r_num(-0.1, 0.1);
      vel.z += r_num(-0.1, 0.1);

      double delta = ((double)worldX + halfSideX) - pos.x;
      if (abs(delta) > (double)sideLengthX * 0.4) {
        vel.x = -vel.x;
      }

      delta = ((double)worldZ + halfSideZ) - pos.z;
      if (abs(delta) > (double)sideLengthZ * 0.4) {
        vel.z = -vel.z;
      }
    }
  }
}
Ejemplo n.º 9
0
void CChildView::OnBpnetRecognize() 
{
	// TODO: Add your command handler code here
	OnImgprcAll();
	//判断是否经过了归一划的处理
	if(gyhfinished==false)
	{
		//如果没有进行提示错误并返回
		::MessageBox(NULL,"没有进行归一划预处理",NULL,MB_ICONSTOP);
		return;
	}
	//获得指向DIB的指针
	BYTE *lpDIB=(BYTE*)::GlobalLock((HGLOBAL) m_hDIB);
	
	//获得指向DIB象素的指针,并指向象素的起始位置
	BYTE *lpDIBBits =(BYTE*)::FindDIBBits((char *)lpDIB);
	
	//获得颜色信息
	int numColors=(int) ::DIBNumColors((char *)lpDIB);
	//不是灰度图返回
    if (numColors!=256) 
	{
		::GlobalUnlock((HGLOBAL) m_hDIB);
		::MessageBox(NULL,"只能处理256色图像",NULL,MB_ICONSTOP);
		return;
	}
	
	//获取图像的宽度
    LONG lWidth = (LONG) ::DIBWidth((char *)lpDIB); 
	
	//获取图像的高度
	LONG lHeight = (LONG) ::DIBHeight((char *)lpDIB);
	
	//计算图像每行的字节数
	LONG lLineByte = (lWidth+3)/4*4; 
	
	//归一化的宽度
	LONG lSwidth = w_sample;
	
	//归一化的高度
	LONG LSheight = h_sample;
	
	// 读取结点信息
	int n[3];
	if(r_num(n,"num")==false)
		return;
	//获得输入层结点数目
	int  n_in=n[0];
	//获得隐层结点数目
	int  n_hidden=n[1];
	//获得输出层结点数目
	int  n_out=n[2];  
	
	//判断待识别样本的归一划信息是否与训练时相同
	if(n_in!=lSwidth*LSheight)
	{
		//如果不相同提示错误并返回
		::MessageBox(NULL,"归一划尺寸与上一次训练时不一致",NULL,MB_ICONSTOP);
		return;
	}
	
	//指向输入样本的特征向量的指针  
	double **data_in;
	//从输入的训练样本中提取特征向量
	data_in = code ( lpDIBBits, digicount,  lLineByte, lSwidth, LSheight);
	
	//根据提取的特征进行样本识别
	CodeRecognize(data_in, digicount,n_in,n_hidden,n_out);
	::GlobalUnlock(m_hDIB);
	
	CDC* pDC=GetDC();
	DisplayDIB(pDC,m_hDIB);
	
}