Esempio n. 1
0
inline void Mat2d :: AddDiadicProduct (double alpha, Vec2d & v)
{
  coeff[0] += alpha * v.X() * v.X();
  coeff[1] += alpha * v.X() * v.Y();
  coeff[2] += alpha * v.Y() * v.X();
  coeff[3] += alpha * v.Y() * v.Y();
}
Esempio n. 2
0
double Angle (const Vec2d & v)
{
  if (v.X() == 0 && v.Y() == 0)
    return 0;
    
  double ang = atan2 (v.Y(), v.X());
  if (ang < 0) ang+= 2 * M_PI;
  return ang;
}
Esempio n. 3
0
inline void Mat2d :: SolvePositiveDefinite (const Vec2d & rhs, Vec2d & x) const
{
  double a = max2(coeff[0], 1e-8);
  double b = coeff[1] / a;
  double c = coeff[2] / a;
  double d = max2(coeff[3] - a *b * c, 1e-8);

  x.X() = (rhs.X() - b * rhs.Y()) / a;
  x.Y() = rhs.Y() / d - c * x.X();
}
Esempio n. 4
0
inline void Mat2d :: Solve (const Vec2d & rhs, Vec2d & x) const
{
  double det = Det();
  
  if (det == 0)
    MyError ("Mat2d::Solve: zero determinant");
  else
    {
      x.X() = (coeff[3] * rhs.X() - coeff[1] * rhs.Y()) / det;
      x.Y() = (-coeff[2] * rhs.X() + coeff[0] * rhs.Y()) / det;
    }
}
Esempio n. 5
0
bool Slider::isWithinBounds(Vec2d &point)
{
	point.setY(game->getDisplay()->getDimensions().Y() - point.Y());

	Vec2d pos = mPosition + mMenuPosition;

	pos.addX(mSliderPosition);

	return (point.X() >= pos.X() &&
			point.Y() >= pos.Y() &&
			point.X() <= pos.X() + 32 &&
			point.Y() <= pos.Y() + 32
			);
}
Esempio n. 6
0
bool Button::isWithinBounds(Vec2d point)
{
	point.setY(game->getDisplay()->getDimensions().Y() - point.Y());

	/*point *= -1;

	point += 1.0f;*/

	Vec2d pos = mPosition + mMenuPosition;
	return (point.X() >= pos.X() &&
			point.Y() >= pos.Y() &&
			point.X() <= pos.X() + getWidth() &&
			point.Y() <= pos.Y() + getHeight()
			);
}
Esempio n. 7
0
float netrule :: CalcLineError (int li, const Vec2d & v) const
{
  float dx = v.X() - linevecs.Get(li).X();
  float dy = v.Y() - linevecs.Get(li).Y();

  const threefloat * ltf = &linetolerances.Get(li);
  return ltf->f1 * dx * dx + ltf->f2 * dx * dy + ltf->f3 * dy * dy;
}
Esempio n. 8
0
int SolveLinearSystemLS2 (const Vec3d & col1,
			 const Vec3d & col2,
			 const Vec2d & rhs,
			 Vec3d & sol, double & x, double & y)
{
  double a11 = col1 * col1;
  double a12 = col1 * col2;
  double a22 = col2 * col2;
  
  double det = a11 * a22 - a12 * a12;

  if (fabs (det) <= 1e-12 * col1.Length() * col2.Length() || 
      col1.Length2() == 0 || col2.Length2() == 0)
    {
      sol = Vec3d (0, 0, 0);
      x = 0; y = 0;
      return 1;
    }
  
  Vec2d invrhs;
  invrhs.X() = ( a22 * rhs.X() - a12 * rhs.Y()) / det;
  invrhs.Y() = (-a12 * rhs.X() + a11 * rhs.Y()) / det;

  sol.X() = invrhs.X() * col1.X() + invrhs.Y() * col2.X();
  sol.Y() = invrhs.X() * col1.Y() + invrhs.Y() * col2.Y();
  sol.Z() = invrhs.X() * col1.Z() + invrhs.Y() * col2.Z();

  x = invrhs.X();
  y = invrhs.Y();

  return 0;

  /*
  Vec3d inv1, inv2;
  int err = 
    PseudoInverse (col1, col2, inv1, inv2);

   sol = rhs.X() * inv1 + rhs.Y() * inv2;
   return err;
  */
}
Esempio n. 9
0
CircleSeg<D> :: CircleSeg (const GeomPoint<D> & ap1, 
			   const GeomPoint<D> & ap2,
			   const GeomPoint<D> & ap3)
  : p1(ap1), p2(ap2), p3(ap3)
{
  Vec<D> v1,v2;
  
  v1 = p1 - p2;
  v2 = p3 - p2;
  
  Point<D> p1t(p1+v1);
  Point<D> p2t(p3+v2);

  // works only in 2D!!!!!!!!!
    
  Line2d g1t,g2t;

  g1t.P1() = Point<2>(p1(0),p1(1));
  g1t.P2() = Point<2>(p1t(0),p1t(1));
  g2t.P1() = Point<2>(p3(0),p3(1));
  g2t.P2() = Point<2>(p2t(0),p2t(1));

  Point<2> mp = CrossPoint (g1t,g2t);

  pm(0) = mp(0); pm(1) = mp(1);
  radius  = Dist(pm,StartPI());
  Vec2d auxv;
  auxv.X() = p1(0)-pm(0); auxv.Y() = p1(1)-pm(1);
  w1      = Angle(auxv);
  auxv.X() = p3(0)-pm(0); auxv.Y() = p3(1)-pm(1);
  w3      = Angle(auxv);
  if ( fabs(w3-w1) > M_PI )
    {  
      if ( w3>M_PI )   w3 -= 2*M_PI;
      if ( w1>M_PI )   w1 -= 2*M_PI;
    }
}
Esempio n. 10
0
int SolveLinearSystemLS (const Vec3d & col1,
			 const Vec3d & col2,
			 const Vec2d & rhs,
			 Vec3d & sol)
{
  double a11 = col1 * col1;
  double a12 = col1 * col2;
  double a22 = col2 * col2;
  
  double det = a11 * a22 - a12 * a12;

  if (det*det <= 1e-24 * a11 * a22)
    {
      sol = Vec3d (0, 0, 0);
      return 1;
    }
  
  Vec2d invrhs;
  invrhs.X() = ( a22 * rhs.X() - a12 * rhs.Y()) / det;
  invrhs.Y() = (-a12 * rhs.X() + a11 * rhs.Y()) / det;

  sol.X() = invrhs.X() * col1.X() + invrhs.Y() * col2.X();
  sol.Y() = invrhs.X() * col1.Y() + invrhs.Y() * col2.Y();
  sol.Z() = invrhs.X() * col1.Z() + invrhs.Y() * col2.Z();

  return 0;

  /*
  Vec3d inv1, inv2;
  int err = 
    PseudoInverse (col1, col2, inv1, inv2);

   sol = rhs.X() * inv1 + rhs.Y() * inv2;
   return err;
  */
}
Esempio n. 11
0
void Sprite::drawPlain(Vec2d &location, Vec2d &bounds, Vec2d &scale)
{
	GLfloat left = convertScale(mTexPosition.X(), 0, mpTexture->getWidth(), 0.0f, 1.0f);
	GLfloat right = convertScale(mTexPosition.X() + bounds.X(), 0, mpTexture->getWidth(), 0.0f, 1.0f);

	GLfloat up = convertScale(mTexPosition.Y() + bounds.Y(), 0, mpTexture->getHeight(), 1.0f, 0.0f);
	GLfloat down = convertScale(mTexPosition.Y(), 0, mpTexture->getHeight(), 1.0f, 0.0f);

	// Front Face

	glTexCoord2f(left,up);
	glVertex3f(-((bounds.X()/bounds.Y()) * scale.X())/2, -scale.Y()/2, 0.0f);              // Top Left

	glTexCoord2f(right,up);
	glVertex3f(/*mpTexture->getRatio()*/((bounds.X()/bounds.Y()) * scale.X())/2, -scale.Y()/2, 0.0f);              // Top Right

	glTexCoord2f(right,down);
	glVertex3f( /*mpTexture->getRatio()*/((bounds.X()/bounds.Y()) * scale.X())/2, scale.Y()/2, 0.0f);              // Bottom Right

	glTexCoord2f(left,down);
	glVertex3f(-((bounds.X()/bounds.Y()) * scale.X())/2,scale.Y()/2, 0.0f);              // Bottom Left

}
Esempio n. 12
0
void netrule :: SetFreeZoneTransformation (const Vector & devp, int tolclass)
{
  double lam1 = 1.0/tolclass;
  double lam2 = 1.-lam1;

  double mem1[100], mem2[100], mem3[100];

  int vs = oldutofreearea.Height();
  FlatVector devfree(vs, mem1);

  int fzs = freezone.Size();
  transfreezone.SetSize (fzs);

  if (tolclass <= oldutofreearea_i.Size())
    {
      oldutofreearea_i[tolclass-1] -> Mult (devp, devfree);

      Array<Point2d> & fzi = *freezone_i[tolclass-1];
      for (int i = 0; i < fzs; i++)
	{
	  transfreezone[i].X() = fzi[i].X() + devfree[2*i];
	  transfreezone[i].Y() = fzi[i].Y() + devfree[2*i+1];
	}
    }
  else
    {
      FlatVector devfree1(vs, mem2);
      FlatVector devfree2(vs, mem3);

      oldutofreearea.Mult (devp, devfree1);
      oldutofreearealimit.Mult (devp, devfree2);
      devfree.Set2 (lam1, devfree1, lam2, devfree2);

      for (int i = 0; i < fzs; i++)
	{
	  transfreezone[i].X() = lam1 * freezone[i].X() + lam2 * freezonelimit[i].X() + devfree[2*i];
	  transfreezone[i].Y() = lam1 * freezone[i].Y() + lam2 * freezonelimit[i].Y() + devfree[2*i+1];
	}
    }


  if (fzs > 0)
    {
      fzmaxx = fzminx = transfreezone[0].X();
      fzmaxy = fzminy = transfreezone[0].Y();
    }

  for (int i = 1; i < fzs; i++)
    {
      if (transfreezone[i].X() > fzmaxx) fzmaxx = transfreezone[i].X();
      if (transfreezone[i].X() < fzminx) fzminx = transfreezone[i].X();
      if (transfreezone[i].Y() > fzmaxy) fzmaxy = transfreezone[i].Y();
      if (transfreezone[i].Y() < fzminy) fzminy = transfreezone[i].Y();
    }

  for (int i = 0; i < fzs; i++)
    {
      Point2d p1 = transfreezone[i];
      Point2d p2 = transfreezone[(i+1) % fzs];

      Vec2d vn (p2.Y() - p1.Y(), p1.X() - p2.X());

      double len2 = vn.Length2();

      if (len2 < 1e-10)
	{
	  freesetinequ(i, 0) = 0;
	  freesetinequ(i, 1) = 0;
	  freesetinequ(i, 2) = -1;
	}
      else
	{
	  vn /= sqrt (len2);    // scaling necessary ?

	  freesetinequ(i,0) = vn.X(); 
	  freesetinequ(i,1) = vn.Y(); 
	  freesetinequ(i,2) = -(p1.X() * vn.X() + p1.Y() * vn.Y());
	}
    }
}
Esempio n. 13
0
//Peter: Used great billboard drawing trick from http://www.lighthouse3d.com/opengl/billboarding/index.php?billCheat.
void Sprite::drawScaledTintedRotated(Vec3d &location, Vec2d &scale, Color &color, float rotation)
{

	GLfloat left = convertScale(mTexPosition.X(), 0, mpTexture->getWidth(), 0.0f, 1.0f);
	GLfloat right = convertScale(mTexPosition.X() + mSize.X(), 0, mpTexture->getWidth(), 0.0f, 1.0f);

	GLfloat up = convertScale(mTexPosition.Y() + mSize.Y(), 0, mpTexture->getHeight(), 1.0f, 0.0f);
	GLfloat down = convertScale(mTexPosition.Y(), 0, mpTexture->getHeight(), 1.0f, 0.0f);

	glPushMatrix();

	glTranslatef(location.X, location.Y, location.Z);

	glPushMatrix();

	//glTranslatef(mpTexture->getRatio()*0.5,0,0);

	mpTexture->setAsActiveTexture();

	float modelview[16];
	int i,j;

	// save the current modelview matrix
	glPushMatrix();

	// get the current modelview matrix
	glGetFloatv(GL_MODELVIEW_MATRIX , modelview);

	// undo all rotations
	// beware all scaling is lost as well 
	for( i=0; i<3; i++ ) 
		for( j=0; j<3; j++ ) 
		{
			if ( i==j )
				modelview[i*4+j] = 1.0;
			else
				modelview[i*4+j] = 0.0;
		}

	// set the modelview with no rotations and scaling
	glLoadMatrixf(modelview);

	glRotatef(rotation, 0.0, 0.0, 1.0);

	//cwc::glShader *shader = (*game->getShaderManager())[0];

	//shader->begin();

	glBegin(GL_QUADS);
	// Front Face

	//Set tint.
	glColor3f(color.r, color.g, color.b);

	glTexCoord2f(left,up);
	glVertex3f(-((mSize.X()/mSize.Y()) * scale.X())/2, -scale.Y()/2, 0.0f);              // Top Left

	glTexCoord2f(right,up);
	glVertex3f(/*mpTexture->getRatio()*/((mSize.X()/mSize.Y()) * scale.X())/2, -scale.Y()/2, 0.0f);              // Top Right

	glTexCoord2f(right,down);
	glVertex3f( /*mpTexture->getRatio()*/((mSize.X()/mSize.Y()) * scale.X())/2, scale.Y()/2, 0.0f);              // Bottom Right

	glTexCoord2f(left,down);
	glVertex3f(-((mSize.X()/mSize.Y()) * scale.X())/2,scale.Y()/2, 0.0f);              // Bottom Left

	glEnd();

	//shader->end();

	if(game->getWireframeBoundingBoxMode())
	{
		glDisable(GL_TEXTURE_2D);

		glLineWidth(10);

		glBegin(GL_LINES);
		// Front Face

		//Set tint.
		glColor3f(color.r, color.g, color.b);

		glTexCoord2f(left,up);
		glVertex3f(-((mSize.X()/mSize.Y()) * scale.X())/2, -scale.Y()/2, 0.0f);              // Top Left
		glVertex3f(/*mpTexture->getRatio()*/((mSize.X()/mSize.Y()) * scale.X())/2, -scale.Y()/2, 0.0f);

		glTexCoord2f(right,up);
		glVertex3f(/*mpTexture->getRatio()*/((mSize.X()/mSize.Y()) * scale.X())/2, -scale.Y()/2, 0.0f);              // Top Right
		glVertex3f( /*mpTexture->getRatio()*/((mSize.X()/mSize.Y()) * scale.X())/2, scale.Y()/2, 0.0f);

		glTexCoord2f(right,down);
		glVertex3f( /*mpTexture->getRatio()*/((mSize.X()/mSize.Y()) * scale.X())/2, scale.Y()/2, 0.0f);              // Bottom Right
		glVertex3f(-((mSize.X()/mSize.Y()) * scale.X())/2,scale.Y()/2, 0.0f);

		glTexCoord2f(left,down);
		glVertex3f(-((mSize.X()/mSize.Y()) * scale.X())/2,scale.Y()/2, 0.0f);              // Bottom Left
		glVertex3f(-((mSize.X()/mSize.Y()) * scale.X())/2, -scale.Y()/2, 0.0f);

		glEnd();

		glEnable(GL_TEXTURE_2D);
	}

	glPopMatrix();

	// restores the modelview matrix
	glPopMatrix();

	glPopMatrix();
}
Esempio n. 14
0
inline  void Mat2d :: MultTrans (const Vec2d & v, Vec2d & prod) const
{
  prod.X() = coeff[0] * v.X() + coeff[2] * v.Y();
  prod.Y() = coeff[1] * v.X() + coeff[3] * v.Y();
}
Esempio n. 15
0
inline void PmP (const Point2d & p1, const Point2d & p2, Vec2d & v)
  {
  v.X() = p1.X() - p2.X();
  v.Y() = p1.Y() - p2.Y();
  }
Esempio n. 16
0
inline void PpSmV (const Point2d & p1, double s,
                   const Vec2d & v, Point2d & p2)
  {
  p2.X() = p1.X() + s * v.X();
  p2.Y() = p1.Y() + s * v.Y();
  }
Esempio n. 17
0
inline Vec2d operator* (double scal, const Vec2d & v)
  {
  return Vec2d (scal * v.X(), scal * v.Y());
  }
Esempio n. 18
0
inline Vec2d operator+ (const Vec2d & v1, const Vec2d & v2)
  {
  return Vec2d (v1.X() + v2.X(), v1.Y() + v2.Y());
  }
Esempio n. 19
0
inline Point2d operator+ (const Point2d & p1, const Vec2d & v)
  {
  return Point2d (p1.X() + v.X(), p1.Y() + v.Y());
  }
Esempio n. 20
0
 friend double Cross (const Vec2d & v1, const Vec2d & v2)
   { return double(v1.X()) * double(v2.Y()) -
            double(v1.Y()) * double(v2.X()); }
Esempio n. 21
0
//Peter: Used great billboard drawing trick from http://www.lighthouse3d.com/opengl/billboarding/index.php?billCheat.
void Sprite::drawScaled(Vec3d &location, Vec2d &scale)
{

	GLfloat left = convertScale(mTexPosition.X(), 0, mpTexture->getWidth(), 0.0f, 1.0f);
	GLfloat right = convertScale(mTexPosition.X() + mSize.X(), 0, mpTexture->getWidth(), 0.0f, 1.0f);

	GLfloat up = convertScale(mTexPosition.Y() + mSize.Y(), 0, mpTexture->getHeight(), 1.0f, 0.0f);
	GLfloat down = convertScale(mTexPosition.Y(), 0, mpTexture->getHeight(), 1.0f, 0.0f);

	glPushMatrix();

	glTranslatef(location.X, location.Y, location.Z);

	glPushMatrix();

	//glTranslatef(mpTexture->getRatio()*0.5,0,0);

	mpTexture->setAsActiveTexture();

	float modelview[16];
	int i,j;

	// save the current modelview matrix
	glPushMatrix();

	// get the current modelview matrix
	glGetFloatv(GL_MODELVIEW_MATRIX , modelview);

	// undo all rotations
	// beware all scaling is lost as well 
	for( i=0; i<3; i++ ) 
		for( j=0; j<3; j++ ) 
		{
			if ( i==j )
				modelview[i*4+j] = 1.0;
			else
				modelview[i*4+j] = 0.0;
		}

	// set the modelview with no rotations and scaling
	glLoadMatrixf(modelview);

	glBegin(GL_QUADS);
	// Front Face
	glColor3f(1,1,1);

	glTexCoord2f(left,up);
	glVertex3f(-((mSize.X()/mSize.Y()) * scale.X())/2, -scale.Y()/2, 0.0f);              // Top Left

	glTexCoord2f(right,up);
	glVertex3f(/*mpTexture->getRatio()*/((mSize.X()/mSize.Y()) * scale.X())/2, -scale.Y()/2, 0.0f);              // Top Right

	glTexCoord2f(right,down);
	glVertex3f( /*mpTexture->getRatio()*/((mSize.X()/mSize.Y()) * scale.X())/2, scale.Y()/2, 0.0f);              // Bottom Right

	glTexCoord2f(left,down);
	glVertex3f(-((mSize.X()/mSize.Y()) * scale.X())/2,scale.Y()/2, 0.0f);              // Bottom Left

	glEnd();

	glPopMatrix();

	// restores the modelview matrix
	glPopMatrix();

	glPopMatrix();
}
Esempio n. 22
0
GLvoid Font::print(std::string &msg, float x, float y)					// Custom GL "Print" Routine
{
	glPushMatrix();

	glTranslatef(x, y, 0);

	Vec2d charPos;

	//mpFontTexture->setAsActiveTexture();

	glDisable(GL_LINES);
	glEnable(GL_TEXTURE_2D);

	char c = 'A';

	for(size_t i = 0; i < msg.length(); ++i)
	{
		//charPos.setX(fmod(mCharDimensions.X() * msg[i], mpFontTexture->getWidth()));
		//charPos.setY((((mCharDimensions.X() * msg[i]) - fmod(mCharDimensions.X() * msg[i], mpFontTexture->getWidth())) / mpFontTexture->getWidth()) * mCharDimensions.Y());
		
		/*charPos.setX(msg[i] % 16 * mCharDimensions.X());
		charPos.setY(256 - (msg[i] / 16 + 1) * mCharDimensions.Y());*/

		c = msg[i];

		//Support line endings.
		if(c == '\n' || c == '\r')
		{
			glTranslatef(0, getHeight(), 0);
			continue;
		}

		GlyphMetrics &glyph = (*mpFontMetrics)[c];

		charPos = glyph.mPos;

		//charPos.setY(-charPos.Y() + mpFontTexture->getHeight());
		charPos = charPos / mpFontTexture->getSizeVec2d();

		mpFontTexture->setAsActiveTexture();

		glBegin(GL_QUADS);

		glColor3f(1,1,1);

		
		glTexCoord2f(charPos.X(), 1.0f-(charPos.Y() + glyph.mSize.Y()/mpFontTexture->getHeight()));
		glVertex2f(0,0);

		glTexCoord2f(charPos.X() + glyph.mSize.X()/mpFontTexture->getWidth(), 1.0f-(charPos.Y() + glyph.mSize.Y()/mpFontTexture->getHeight()));
		
		glVertex2f(glyph.mSize.X(), 0);

		glTexCoord2f(charPos.X() + glyph.mSize.X()/mpFontTexture->getWidth(), 1.0f-charPos.Y());
		glVertex2f(glyph.mSize.X(), glyph.mSize.Y());

		glTexCoord2f(charPos.X(), 1.0f-charPos.Y());
		glVertex2f(0, glyph.mSize.Y());

		glEnd();

		glTranslatef(glyph.mSize.X(), 0, 0);
	}

	glDisable(GL_TEXTURE_2D);
	glEnable(GL_LINES);

	glPopMatrix();
	//mpFont->draw(x, y, fmt);
}
Esempio n. 23
0
void Monster::think(const double elapsedTime)
{
    Entity::think(elapsedTime);

    if(!mIsDying && mHealth <= 0)
        kill();

    if(mIsStunned)
    {
        if(mPosition.Y > -0.5)
        {
            mVelocity.Y -= 0.005;
            mPosition += mVelocity;

            if(game->getCurrentMap()->getTile(int(mPosition.X + mVelocity.X), int(mPosition.Z)).type == TYPE_WALL)
            {
                mVelocity.X = -mVelocity.X;

                mVelocity *= MONSTER_DAMPING;

            }
            if(game->getCurrentMap()->getTile(int(mPosition.X), int(mPosition.Z + mVelocity.Z)).type == TYPE_WALL)
            {
                mVelocity.Z = -mVelocity.Z;

                mVelocity *= MONSTER_DAMPING;
            }

        }
        else
        {
            mIsStunned = false;
            mPosition.Y = -0.5;
        }
    }

    if(mIsDying)
    {
        if(mDeathTimer.getElapsedTime() >= 500)
            mShouldDelete = true;

        return;
    }

    if(mIsFrozen)
    {
        if(mFreezeTimer.getElapsedTime() < 5000)
        {
            return;
        }
        else
            setFrozen(false);
    }

    if(mIsFleeing)
    {
        Vec2d motion = Vec2d(playerPos.X-mPosition.X,playerPos.Z-mPosition.Z);

        motion.normalize();

        motion /= 35;

        if((playerPos.X - mPosition.X) + (playerPos.Z - mPosition.Z) < 0.3)
        {
            int goalStr = game->getCurrentMap()->getTile(int(mPosition.X), int(mPosition.Z)).goodCreatureGoal;
            playerPos = mPosition;
            for(int i = -1; i < 2; ++i)
                for(int j = -1; j < 2; ++j)
                    if(game->getCurrentMap()->getTile(i + int(mPosition.X), j + int(mPosition.Z)).type != TYPE_WALL && goalStr < game->getCurrentMap()->getTile(i + int(mPosition.X), j + int(mPosition.Z)).goodCreatureGoal && game->getCurrentMap()->getTile(i + int(mPosition.X), j + int(mPosition.Z)).goodCreatureGoal < 100)
                    {
                        goalStr = game->getCurrentMap()->getTile(i + int(mPosition.X), j + int(mPosition.Z)).goodCreatureGoal;
                        playerPos.X = mPosition.X + i;
                        playerPos.Z = mPosition.Z + j;
                    }
        }

        game->getCurrentMap()->setGoal(int(playerPos.X), int(playerPos.Z), 0);
        game->getCurrentMap()->setGoal(int(mPosition.X), int(mPosition.Z), 0);

        //Increase position of monster.
        mPosition -= Vec3d(motion.X(),0,motion.Y());
    }
    else
    {
        Vec2d motion = Vec2d(playerPos.X-mPosition.X,playerPos.Z-mPosition.Z);

        motion.normalize();

        motion /= 50;

        if((playerPos.X - mPosition.X) + (playerPos.Z - mPosition.Z) < 0.3)
        {
            int goalStr = game->getCurrentMap()->getTile(int(mPosition.X), int(mPosition.Z)).goodCreatureGoal;
            playerPos = mPosition;
            for(int i = -1; i < 2; ++i)
                for(int j = -1; j < 2; ++j)
                    if(game->getCurrentMap()->getTile(i + int(mPosition.X), j + int(mPosition.Z)).type != TYPE_WALL && goalStr < game->getCurrentMap()->getTile(i + int(mPosition.X), j + int(mPosition.Z)).goodCreatureGoal && game->getCurrentMap()->getTile(i + int(mPosition.X), j + int(mPosition.Z)).goodCreatureGoal < 100)
                    {
                        goalStr = game->getCurrentMap()->getTile(i + int(mPosition.X), j + int(mPosition.Z)).goodCreatureGoal;
                        playerPos.X = mPosition.X + i;
                        playerPos.Z = mPosition.Z + j;
                    }
        }

        game->getCurrentMap()->setGoal(int(playerPos.X), int(playerPos.Z), 0);
        game->getCurrentMap()->setGoal(int(mPosition.X), int(mPosition.Z), 0);

        //Increase position of monster.
        mPosition += Vec3d(motion.X(),0,motion.Y());
    }


    /*if(rand() % 500 == 0)
    {
    	attack();
    }

    if(rand() % 5000 == 0)
    {
    	makeMonsterNoise();
    }*/

    if(mVoice)
        mVoice->setPosition(mPosition);
}
Esempio n. 24
0
double FastAngle (const Vec2d & v)
{
  return Fastatan2 (v.X(), v.Y());
}
Esempio n. 25
0
void Button::draw()
{
	Color *color;

	if(mHover && !mPressed)
		color = &mSelectedColor;
	else
		color = &mBackColor;

	/*mpBuffer->fill(*color);

	//Draw outline.
	mpBuffer->drawRect(Vec2d(0,0), mpBuffer->getDimensions()-2, mForeColor, 2.0);

	//Draw button caption.
	mpBuffer->writeText(mText,(getDimensions() - mTextDimensions)/2, *mpFont, mForeColor);*/

	glPushMatrix();

	glTranslatef(mPosition.X(), mPosition.Y(), 0);

	//***********
	//Draw button.
	//***********

	glBegin(GL_QUADS);
	
	color->setActiveColor();

	glVertex2f(0,0);
	glVertex2f(mDimensions.X(), 0);
	glVertex2f(mDimensions.X(), mDimensions.Y());
	glVertex2f(0, mDimensions.Y());

	glEnd();

	//************
	//Draw outline
	//************

	glBegin(GL_LINES);
	
	//Set line width to 2.0.
	glLineWidth(2.0f);

	mForeColor.setActiveColor();

	glVertex2f(0,0);
	glVertex2f(mDimensions.X(), 0);

	glVertex2f(mDimensions.X(), 0);
	glVertex2f(mDimensions.X(), mDimensions.Y());

	glVertex2f(mDimensions.X(), mDimensions.Y());
	glVertex2f(0, mDimensions.Y());

	glVertex2f(0, mDimensions.Y());
	glVertex2f(0,0);

	glEnd();

	glPopMatrix();

	/*glPushMatrix();

	Vec2d center = (getDimensions() - mTextDimensions)/2;

	glTranslatef(center.X(), center.Y(), 0);
	mpFont->print(mText.c_str());

	glPopMatrix();*/

	Vec2d center = mPosition + (getDimensions() - mTextDimensions)/2;

	mpFont->print(mText, center.X(), center.Y());

	//mpBuffer->draw(buffer,mPosition);
}
Esempio n. 26
0
 friend double operator* (const Vec2d & v1, const Vec2d & v2)
   { return v1.X() * v2.X() + v1.Y() * v2.Y(); }