Exemplo n.º 1
0
void Quaternion::setPow(const Quaternion& q, Real n)
{
	Real mag = q.norm();
	Real immag = q.imNorm();
	Real immaginv;
	if(immag == Zero) immaginv = Zero;  //it's a real number, zero out the imaginary part
	else immaginv = One / immag;
	Real theta = Atan2(immag, q.w);

	Real cntheta = Cos(n*theta);
	Real sntheta = Sin(n*theta);
	Real powm = Pow(mag, n);

	w = powm * cntheta;
	x = powm * sntheta * immaginv * q.x;
	y = powm * sntheta * immaginv * q.y;
	z = powm * sntheta * immaginv * q.z;
}
Exemplo n.º 2
0
//陰陽「太極図」
int CBossChenMiddle::Taikyoku()
{
    flag = 1;
    deffence = 1;
    SetHP(2000);
    SetTime(40);
    Suspend(60);

    for( int i = 0; i < 60; ++i ) {
        x += ( 450 - GetX() ) / 60;
        y += ( GAME_CENTER_Y - GetY() ) / 60;
        mt.Suspend(1);
    }

    CTamaTaikyoku tama;
    tama.x = GetX();
    tama.y = GetY();
    tama.type = 12;
    tama.v = 3;
    int offset = 0.0;
    while(1) {
        for( int i = 0;; i++) {
            //攻撃
            tama.color = 1;
            tama.a = offset;
            g_lTama.Add( tama.Copy() );
            tama.color = 0;
            tama.a = offset + 180;
            g_lTama.Add( tama.Copy() );

            g_pMaterial->sndFire.Play(0);
            double m;
            if( GetDifficult() == DIFF_LUNATIC )
                m = 1.5*(4-GetDifficult());
            else
                m = 2.0*(4-GetDifficult());

            if( i > 120/m )
                offset += 3.0*m*Sin((double)i*2);
            this->Suspend(m);
        }
    }
    return 1;
}
Exemplo n.º 3
0
void create_sloping_cylinder(GLfloat* matrix)
{
    // GLfloat h = 2.03125;
    // GLfloat length = 1;
    glLoadIdentity();
    // setEye();
    glLoadMatrixf(matrix);
    int th2, ph2, i, j, k;
    double height=0.5;
    double radius=0.40710678118;
    glBegin(GL_QUAD_STRIP);
    for (j=0;j<=360;j+=DEF_D) 
    {
         // glColor3f(0,1,0);
      if(j>=90 && j<=270)
      {
        glNormal3f(-Cos(j),0,-Sin(j));
        glVertex3f((radius)*Cos(j),0,(radius)*Sin(j));
        glVertex3f((radius)*Cos(j),-2*height,(radius)*Sin(j));
      }
      else
      {
        glNormal3f(-Cos(j),0,-Sin(j));
        glVertex3f((radius)*Cos(j),-2*height+1-Cos(j)*2*height,(radius)*Sin(j));
        glVertex3f((radius)*Cos(j),-2*height,(radius)*Sin(j));
        
      }
    }
    glEnd();
    glBegin(GL_QUAD_STRIP);
    for (k=0;k<=360;k+=DEF_D) 
    {
      
        glNormal3f(0,-1,0);   
        glVertex3f((radius)*Cos(k),-2*height,(radius)*Sin(k));
        glNormal3f(0,-1,0);   
        glVertex3f((radius-0.0625)*Cos(k),-2*height,(radius-0.0625)*Sin(k));
      
    }
    glEnd();
}
Exemplo n.º 4
0
   Matrix4 &Matrix4::FromRotationZ(float angle)
   {
      // NOTE.  The (x,y,z) coordinate system is assumed to be right-handed.
      // Coordinate axis rotation matrices are of the form
      //   RZ =  cos(t) -sin(t)    0
      //         sin(t)  cos(t)    0
      //           0       0       1
      // where t > 0 indicates a counterclockwise rotation in the xy-plane.

      float fCos = Cos(angle);
      float fSin = Sin(angle);

      m[0][0] = fCos;   m[0][1] = -fSin;  m[0][2] = 0.0f;   m[0][3] = 0.0f;
      m[1][0] = fSin;   m[1][1] =  fCos;  m[1][2] = 0.0f;   m[1][3] = 0.0f;
      m[2][0] = 0.0f;   m[2][1] =  0.0f;  m[2][2] = 1.0f;   m[2][3] = 0.0f;
      m[3][0] = 0.0f;   m[3][1] =  0.0f;  m[3][2] = 0.0f;   m[3][3] = 1.0f;

      return *this;
   }
Exemplo n.º 5
0
// Iterate through the list of active shots and draw them
void DrawShots(void)
{
  for( int i=0; i<UsedShots; i++ )
  {
    int x0, y0, x1, y1;
    int d0 = Shots[i].dist;
    int d1 = d0 + ShotLen;

    int a = Shots[i].ang << 7;
    int cs = -Cos(a), sn = Sin(a);

    x0 = ((sn * d0) + 32768) / 65536 + HCenter;
    y0 = ((cs * d0) + 32768) / 65536 + VCenter;
    x1 = ((sn * d1) + 32768) / 65536 + HCenter;
    y1 = ((cs * d1) + 32768) / 65536 + VCenter;

    line( x0, y0, x1, y1, 1 );
  }
}
Exemplo n.º 6
0
void
rotate(obj *p, double phi, obj *q)
	/* double	phi;	in radians */
{
register double	x, y;
	double	M[6];

	M[3] =   M[0] = Cos(phi);
	M[2] = -(M[1] = Sin(phi));
	if (q == NULL)
		M[4] = M[5] = 0;
	else {
		x = Xformx(q, 1, q->o_x, q->o_y);
		y = Xformy(q, 0, q->o_x, q->o_y);
		M[4] = (1 - M[0]) * x + M[1] * y;
		M[5] = (1 - M[0]) * y - M[1] * x;
	}
	apply(p, M, 1);
}
Exemplo n.º 7
0
void AxisRotationFit(const std::vector<Vector3>& a,const std::vector<Vector3>& b,const Vector3& z,Real& theta)
{
  Assert(!a.empty());
  Assert(a.size()==b.size());
  //min sum||R*a[i]-b[i]||^2
  //  = sum (R*a[i]-b[i]).(R*a[i]-b[i])
  //  = sum a[i].a[i] + b[i].b[i] - 2 b[i].R*a[i]
  //differentiating, get
  //  0 = sum b[i].R'*a[i] = sum b[i].[z]R*a[i]
  //Let s=sin(theta) and c=cos(theta). 
  //  R = cI + (1-c)zz' + s[z]
  //so 
  //  0 = sum c*b[i]'[z]a[i] + (1-c)b[i]'[z]zz'a[i] + sb[i]'[z][z]a[i]
  //    = c*sum b[i]'[z]a[i] + s*b[i]'[z][z]a[i]
  // [z] = [0 -z y]
  //       [z 0 -x]
  //       [-y x 0]
  // [z]^2 = [-zz-yy  xy       xz   ]
  //         [xy     -xx-zz    yz   ]
  //         [xz      yz      -xx-yy]
  //collecting terms by s and c,
  //get s(sum -axbx-ayby) + c(sum axby-aybx) = 0
  //solve using theta = atan(sum axby-aybx / sum -axbx-ayby)
  //is it theta or theta+pi?
  Matrix3 zcross,zcross2;
  zcross.setCrossProduct(z);
  zcross2.mul(zcross,zcross);
  Real scoeff=0,ccoeff=0;
  for(size_t i=0;i<a.size();i++)
    scoeff += b[i].dot(zcross2*a[i]);
  for(size_t i=0;i<b.size();i++)
    ccoeff += b[i].dot(zcross*a[i]);

  if(FuzzyZero(scoeff) && FuzzyZero(ccoeff))
    theta=0;
  else 
    theta = Atan2(-ccoeff,scoeff);
   
  Real c=Cos(theta),s=Sin(theta);
  if(c*scoeff-s*ccoeff > 0) {
    theta += Pi;
  }
}
Exemplo n.º 8
0
void DebugRenderer::AddCircle(const Vector3& center, const Vector3& normal, float radius, const Color& color, int steps, bool depthTest)
{
    Quaternion orientation;
    orientation.FromRotationTo(Vector3::UP, normal.Normalized());
    Vector3 p = orientation * Vector3(radius, 0, 0) + center;
    unsigned uintColor = color.ToUInt();

    for(int i = 1; i <= steps; ++i)
    {
        const float angle = (float)i / (float)steps * 360.0f;
        Vector3 v(radius * Cos(angle), 0, radius * Sin(angle));
        Vector3 c = orientation * v + center;
        AddLine(p, c, uintColor, depthTest);
        p = c;
    }

    p = center + normal * (radius / 4.0f);
    AddLine(center, p, uintColor, depthTest);
}
Exemplo n.º 9
0
//----------------------------------------------------------------//
void MOAIDraw::DrawEllipseOutline ( float x, float y, float xRad, float yRad, u32 steps ) {

	MOAIGfxDevice& gfxDevice = MOAIGfxDevice::Get ();

	float angle = ( float )TWOPI / ( float )steps;
	float angleStep = ( float )PI;
	
	gfxDevice.BeginPrim ( GL_LINE_LOOP );
	
	for ( u32 i = 0; i < steps; ++i, angleStep += angle ) {
		gfxDevice.WriteVtx (
			x + ( Sin ( angleStep ) * xRad ),
			y + ( Cos ( angleStep ) * yRad ),
			0.0f
		);
		gfxDevice.WriteFinalColor4b ();
	}
	gfxDevice.EndPrim ();
}
Exemplo n.º 10
0
func FxMoveToTimer(object target, proplist fx, int time)
{
	if(!master)
	{
		KillBall();
		return;
	}
		
	if(GetEffect("Blocked", this))
	{
		ox=GetX();
		oy=GetY();
		return;
	}
	
	DrawParticleLine("Flash", 0, 0, ox-GetX(), oy-GetY(), 1, 0, 0, 15, movetrailparticles);

	if(time%7 == 0)
	{
		for(var i = 0; i < 360; i+=5)
		{
			CreateParticle("Flash", Sin(i, 3), -Cos(i, 5), 0, 0, 10, moveparticle2, 2);
		}
	}

	MoveToPos(fx.x, fx.y);
	
	ox=GetX();
	oy=GetY();
	
	var dst = Distance(GetX(), GetY(), fx.x, fx.y);
	if(dst < 5)
	{
		SetXDir(0);
		SetYDir(0);
		CheckForEnemies(AttackSize);
		Idle();
		
		CreateParticle("StarSpark", 0, 0, 0, 0, 10, moveparticle, 5);
		
		return -1;
	}
}
Exemplo n.º 11
0
    //
    // RotationAroundAxis
    //
    void Mat4::RotationAroundAxis( const Vec3<float>& Axis, float Angle )
    {
	    // x^2 + (1 - x^2) * cos(a) => x^2 + cos(a) - x^2 * cos(a) => 
        // x^2 * (1 - cos(a)) + cos(a)

    #ifdef _DEBUG
	    Axis.Assume();
    #endif

        float Rad = Radians( Angle );

        float s = Sin( Rad );
        float c = Cos( Rad );
	    float d = 1.0f - c;

	    float xs = Axis.x * s;
	    float ys = Axis.y * s;
	    float zs = Axis.z * s;

	    float xyd = Axis.x * Axis.y * d;
	    float xzd = Axis.x * Axis.z * d;
	    float yzd = Axis.y * Axis.z * d;

	    m[ 0 ].x = Axis.x * Axis.x * d + c; 
	    m[ 0 ].y = xyd + zs;
	    m[ 0 ].z = xzd - ys;
        m[ 0 ].w = 0.0f;

	    m[ 1 ].x = xyd - zs;
	    m[ 1 ].y = Axis.y * Axis.y * d + c; 
	    m[ 1 ].z = yzd + xs;
        m[ 1 ].w = 0.0f;

	    m[ 2 ].x = xzd + ys;
	    m[ 2 ].y = yzd - xs;
	    m[ 2 ].z = Axis.z * Axis.z * d + c;
        m[ 2 ].w = 0.0f;

        m[ 3 ].x = 0.0f;
	    m[ 3 ].y = 0.0f;
	    m[ 3 ].z = 0.0f;
	    m[ 3 ].w = 1.0f;
    }
Exemplo n.º 12
0
void LineBatcher::DrawEllipsoid(const Vector& Center, const Vector& Extents,
                                unsigned int Color) {
#if BUILD_RELEASE
  if (m_IsDebug) {
    return;
  }
#endif

  STATICHASH(DebugSphereResolution);
  uint Resolution = ConfigManager::GetInt(sDebugSphereResolution, 16);
  uint TwoR = Resolution * 2;

  m_AddPositions.Resize(Resolution * 3);
  m_AddColors.Resize(Resolution * 3);
  m_AddIndices.Resize(Resolution * 6);

  for (uint i = 0; i < Resolution * 3; ++i) {
    m_AddColors[i] = Color;
  }

  float Mult = TWOPI / (float)Resolution;

  for (uint i = 0; i < Resolution; ++i) {
    float u = Cos((float)i * Mult);
    float v = Sin((float)i * Mult);
    m_AddPositions[i] =
        Vector(Center.x + u * Extents.x, Center.y + v * Extents.y, Center.z);
    m_AddPositions[i + Resolution] =
        Vector(Center.x + u * Extents.x, Center.y, Center.z + v * Extents.z);
    m_AddPositions[i + TwoR] =
        Vector(Center.x, Center.y + u * Extents.y, Center.z + v * Extents.z);
    m_AddIndices[i * 2] = (index_t)(i);
    m_AddIndices[i * 2 + 1] = (index_t)((i + 1) % Resolution);
    m_AddIndices[i * 2 + TwoR] = (index_t)(i + Resolution);
    m_AddIndices[i * 2 + TwoR + 1] =
        (index_t)(((i + 1) % Resolution) + Resolution);
    m_AddIndices[i * 2 + TwoR * 2] = (index_t)(i + TwoR);
    m_AddIndices[i * 2 + TwoR * 2 + 1] =
        (index_t)(((i + 1) % Resolution) + TwoR);
  }

  Add(m_AddPositions, m_AddColors, m_AddIndices);
}
Exemplo n.º 13
0
void FoxLi( Matrix<Complex<Real>>& A, Int n, Real omega )
{
    DEBUG_CSE
    typedef Complex<Real> C;
    const Real pi = 4*Atan( Real(1) );
    const C phi = Sqrt( C(0,omega/pi) ); 
    
    // Compute Gauss quadrature points and weights
    Matrix<Real> d, e; 
    Zeros( d, n, 1 );
    e.Resize( n-1, 1 );
    for( Int j=0; j<n-1; ++j )
    {
        const Real betaInv = 2*Sqrt(1-Pow(j+Real(1),-2)/4);
        e(j) = 1/betaInv;
    }
    Matrix<Real> x, Z;
    HermitianTridiagEig( d, e, x, Z, UNSORTED );
    auto z = Z( IR(0), ALL );
    Matrix<Real> sqrtWeights( z ), sqrtWeightsTrans;
    for( Int j=0; j<n; ++j )
        sqrtWeights(0,j) = Sqrt(Real(2))*Abs(sqrtWeights(0,j));
    herm_eig::Sort( x, sqrtWeights, ASCENDING );
    Transpose( sqrtWeights, sqrtWeightsTrans );

    // Form the integral operator
    A.Resize( n, n );
    for( Int j=0; j<n; ++j )
    {
        for( Int i=0; i<n; ++i )
        {
            const Real theta = -omega*Pow(x(i)-x(j),2);
            const Real realPart = Cos(theta);
            const Real imagPart = Sin(theta);
            A(i,j) = phi*C(realPart,imagPart);
        }
    }

    // Apply the weighting
    DiagonalScale( LEFT, NORMAL, sqrtWeightsTrans, A );
    DiagonalScale( RIGHT, NORMAL, sqrtWeightsTrans, A );
}
Exemplo n.º 14
0
void Player::update(Game* game) {
	frameCount++;

	auto pad = XInput(0);
	pad.setLeftThumbDeadZone();
	pad.setRightThumbDeadZone();

	//move
	if (!Vec2(pad.leftThumbX, pad.leftThumbY).isZero) {
		rad = Atan2(-pad.leftThumbY, pad.leftThumbX);
		pos += Vec2(Cos(rad), Sin(rad)) * 7.5;
	}
	pos = Vec2(Clamp(pos.x, 0.0, static_cast<double>(Game::stageSize.x)), Clamp(pos.y, 0.0, static_cast<double>(Game::stageSize.y)));

	//bomb
	if (Input::KeyX.clicked) {
		game->getBulletManager()->clear();
		game->getEnemyManager()->clear();
	}

	//fire
	if (!Vec2(pad.rightThumbX, pad.rightThumbY).isZero) {
		for (int i : {-1, 1, 0}) {
			const double fireRad = Atan2(-pad.rightThumbY, pad.rightThumbX) + Radians(5 * i);
			if (fireCount % 5 == 0) {
				auto shot = std::make_shared<NormalShot>(pos, fireRad);
				shotManager->add(shot);
			}
		}
	}
	fireCount++;
	shotManager->update(game);

	tracks.push_front(pos);
	if (tracks.size() > 20) tracks.pop_back();

	damageCount++;
	checkBulletHit(game);
	if (frameCount % 10 == 0 && damageCount) shield++;
	shield = Clamp(shield, 0, SHIELD_MAX);
	hp = Clamp(hp, 0, HP_MAX);
}
Exemplo n.º 15
0
////////////////////////////////////////////////////////////////////////////////
// Initialize individual particles
void partinit(particle *part, int i) {
  float v = rand()%1000;   // Velocity
  float th = rand()%360; // Angle

  part[i].active = true;                 // Make ALL the particles active
  part[i].life = 1.0;                    // Give ALL the particles full life
  part[i].fade = frand(100, 0.003);      // Random Fade Speed
  /*part[i].r    = red;               // Red Color
  part[i].g    = green;               // Green Color
  part[i].b    = blue;               // Blue Color
  */part[i].xp   = 0.0;                    // Center
  part[i].yp   = 0.0;                    // Oscilating
  part[i].zp   = 0.0;                    // Center
  part[i].xd   = Sin(th) * v;            // X Speed;
  part[i].yd   = v; //frand(50, -25) * v;     // Y Speed;
  part[i].zd   = Cos(th) * v;            // Z Speed;
  part[i].xg   = 0;                      // No X-Axis pull
  part[i].yg   = -10;                   // Vertical pull down
  part[i].zg   = 0;                      // No Z-Axis pull
}
Exemplo n.º 16
0
//----------------------------------------------------------------//
int MOAIVectorUtil::StrokeWedge ( const MOAIVectorStyle& style, ZLVec2D*& verts, const ZLVec2D& origin, const ZLVec2D& n0, const ZLVec2D& n1, float width ) {
	
	float wedge = n0.Radians ( n1 ); // angle between two normals
	
	u32 steps = style.GetResolutionForWedge ( wedge );
	
	if ( verts ) {
		
		float angle = n0.Radians (); // angle of first normal against x axis
		float angleStep = wedge / ( float )steps;
		
		for ( u32 i = 0; i <= steps; ++i, angle += angleStep ) {
			ZLVec2D v;
			v.mX = origin.mX + ( Cos ( angle ) * width );
			v.mY = origin.mY + ( Sin ( angle ) * width );
			*( verts++ ) = v;
		}
	}
	return ( int )( steps + 1 );
}
Exemplo n.º 17
0
static void sub_80CA8B4(struct Sprite* sprite)
{
    if (TranslateAnimSpriteByDeltas(sprite))
    {
        DestroySprite(sprite);
    }
    else
    {
        if (sprite->data[5] > 0x7F)
        {
            sprite->subpriority = sub_8079E90(gAnimBankTarget) + 1;
        }
        else
        {
            sprite->subpriority = sub_8079E90(gAnimBankTarget) + 6;
        }
        sprite->pos2.x += Sin(sprite->data[5], 5);
        sprite->pos2.y += Cos(sprite->data[5], 14);
        sprite->data[5] = (sprite->data[5] + 15) & 0xFF;
    }
}
Exemplo n.º 18
0
func FillCheck()
  {
  if(!Contained())
      if(Inside(GetR(), 20, 340))
        Hit();
    if(!(iTimer%5))
    {
    var iX = Sin(GetR(), RandomX(-4,4) );
    var iY = -Cos(GetR(), RandomX(-4,1) );
    if(!Contained())
      CreateParticle("NoGravSpark", iX, iY,0,0,RandomX(25, 55),RGBa(255,255,0,120));
    }
  iTimer++;
  if(iTimer>=17)
    {
    if(GetOCF(Contained()) & OCF_CrewMember())
      DoEnergy(+1, Contained());
    iTimer=0;
    }
  return(1);
  }
Exemplo n.º 19
0
/*
 *  cylinder
 *  ------
 *  Draw a cylinder
 *     at (x, y, z)
 *     with radius r and height h
 */
void cylinder(double x,double y,double z,
	      double r,double h)
{
  int i,k;

  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D,currentTexture);
  glPushMatrix();

  /*  Transformation */
  glTranslated(x,y,z);
  glScaled(r,h,r);
  /*  sides */
  glBegin(GL_QUAD_STRIP);
  for (k=0;k<=360;k+=DEF_D) {
    glNormal3f(Cos(k),0,Sin(k));
    // TODO: fix these textures
    glTexCoord2f(-Cos(k),Sin(k));
    glVertex3f(Cos(k),+1,Sin(k));

    glTexCoord2f(Cos(k),Sin(k));
    glVertex3f(Cos(k),-1,Sin(k));
  }
  glEnd();

  /* top and bottom circles */
  /* reuse the currentTexture on top and bottom) */
  for (i=1;i>=-1;i-=2) {
    glBegin(GL_TRIANGLE_FAN);
    glNormal3f(0,i,0);
    glTexCoord2f(0.5,0.5);
    glVertex3f(0,i,0);
    for (k=0;k<=360;k+=DEF_D) {
      glTexCoord2f(0.5*Cos(k)+0.5,0.5*Sin(k)+0.5);
      glVertex3f(i*Cos(k),i,Sin(k));
    }
    glEnd();
  }

  glPopMatrix();
  glDisable(GL_TEXTURE_2D);
}
Exemplo n.º 20
0
/*
 *  drawLight 
 *  ------
 *  Draws the light
 */
void drawLight(void)
{
  /*  Light switch */
  if (toggleLight) {
    /*  Translate intensity to color vectors */
    GLfloat Ambient[]   = {0.01*ambient ,0.01*ambient ,0.01*ambient ,1.0};
    GLfloat Diffuse[]   = {0.01*diffuse ,0.01*diffuse ,0.01*diffuse ,1.0};
    GLfloat Specular[]  = {0.01*specular,0.01*specular,0.01*specular,1.0};
    GLfloat Position[]  = {distance*Sin(lightPh),lightY,distance*Cos(lightPh),1.0};

    /*  Draw light position as sphere (still no lighting here) */
    glColor3fv(white);
    glDisable(GL_LIGHTING);
    sphere(Position[0],Position[1],Position[2], 0.1,0);

    /*  Set ambient, diffuse, specular components and position of light 0 */
    /*
      Light uses the Phong model
      Once light is enabled, colors assigned by glColor* isn't used
      Ambient is light that's been scattered by environment that its direction is impossible to determine
      Diffuse is is light that comes from one direction, so it's brighter if it comes squarely on surface rather than glances off
      Specular is light that comes from a particular direction and bounces off in preferred direction
      Position is the position of our light. In this case it is the same as the sphere.
     */
    glLightfv(GL_LIGHT0,GL_AMBIENT, Ambient);
    glLightfv(GL_LIGHT0,GL_DIFFUSE, Diffuse);
    glLightfv(GL_LIGHT0,GL_POSITION,Position);
    glLightfv(GL_LIGHT0,GL_SPECULAR,Specular);

    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
    glEnable(GL_NORMALIZE);
    glEnable(GL_LIGHTING); 
    glEnable(GL_LIGHT0);
  }
  else {
    glDisable(GL_LIGHTING);
  }
}
Exemplo n.º 21
0
// convert from old version of texture mapping defintion
void CMappingDefinition::ReadOld_t(CTStream &strm) // throw char *
{
  // old texture mapping orientation and offsets structure
  // - obsolete - used only for loading old worlds
  class CTextureMapping_old {
  public:
    ULONG tm_ulFlags;       // flags
    ANGLE tm_aRotation;     // angle of texture rotation
    FLOAT tm_fOffsetU;      // texture offsets (in meters)
    FLOAT tm_fOffsetV;
  } tmo;
  strm.Read_t(&tmo, sizeof(tmo));

  FLOAT fSin = Sin(tmo.tm_aRotation);
  FLOAT fCos = Cos(tmo.tm_aRotation);

  md_fUOffset = -tmo.tm_fOffsetU;
  md_fVOffset = -tmo.tm_fOffsetV;
  md_fUoS = +fCos;
  md_fUoT = -fSin;
  md_fVoS = +fSin;
  md_fVoT = +fCos;
}
Exemplo n.º 22
0
void MtxProjection2(matrix_t row, const float openAngle,
					const float aspectRatio,
					const float zNear, const float zFar)
{
  const float halfAngle = 0.5f * openAngle;
  const float cosOverSin = Cos(halfAngle) / Sin(halfAngle);
  const float w = cosOverSin;
  const float h = w * aspectRatio;
  const float q = zFar / (zFar - zNear);

/*   row[0][0] = w; */
/*   row[1][1] = h; */
/*   row[2][2] = (zFar+zNear)/(zNear-zFar); */
/*   row[3][2] = 2*zFar*zNear/(zNear-zFar); */
/*   row[2][3] = -1.0f; */
/*   row[3][3] = 1.0f; */
/*   row[0][1] = row[0][2] = row[0][3] = */
/*     row[1][0] = row[1][2] = row[1][3] = */
/*     row[2][0] = row[2][1] = */
/*     row[3][0] = row[3][1] = 0.0f; */

  SetProjection(row, w, h, q, zNear);
}
void CEyeBotCircle::MoveAlongCircle() {
   if(m_eState != STATE_MOVE_ALONG_CIRCLE) {
      /* State initialization */
      m_eState = STATE_MOVE_ALONG_CIRCLE;
      m_unWaypoint = 0;
   }
   else {
      if(m_unWaypoint >= CIRCLE_WAYPOINTS) {
         /* State transition */
         GoToCenter();
      }
      else {
         /* State logic */
         m_cTargetPos.Set(
            CIRCLE_RADIUS * Cos(CIRCLE_SLICE * m_unWaypoint),
            CIRCLE_RADIUS * Sin(CIRCLE_SLICE * m_unWaypoint),
            0.0f);
         m_cTargetPos += m_cCircleCenter;
         m_pcPosAct->SetAbsolutePosition(m_cTargetPos);
         ++m_unWaypoint;
      }
   }
}
Exemplo n.º 24
0
void MoveShot( int i )
{
  // We're going to test if the far end of the shot is off the screen yet (that's why we add ShotLen)
  int dist = Shots[i].dist + ShotLen + 1;

  int a = Shots[i].ang << 7;  // scale the angle value back up from when we stored it

  // Compute the rotated location of the shot
  int x = ( Sin(a) * dist + 32768) / 65536;
  int y = (-Cos(a) * dist + 32768) / 65536;

  // If the rotated x or y are outside the range of the display, the shot has gone off the screen
  if( abs(x) >= Width || abs(y) >= Height )
  {
    // out of bounds - remove this shot from the active list
    UsedShots--;
    FreeShots++;

    // Do we still have any shots that are active?
    if( UsedShots )
    {
      // Copy the data for the LAST active shot into this spot in the shots array
      // This compacts the list.
      memcpy( Shots + i, Shots + UsedShots, sizeof(SHOT) );

      // Because we just moved the LAST shot in the list to this spot in the Shots array,
      // the moved entry would get skipped by the updating code, because it has no idea
      // that we changed the list order.  We call MoveShot AGAIN, on the updated entry, so it doesn't get missed.
      // This is overkill for a simple demo, but it's good to know that this kind of thing happens.  :)
      MoveShot( i );
    }
  }
  else
  {
    Shots[i].dist = dist;
  }
}
Exemplo n.º 25
0
global func CreateAttackWave(int angle, int rockets, int anglespread)
{
	var radius = Min(LandscapeWidth()/2, LandscapeHeight()/2);
	var rocket_id = Boomattack;
	// boss
	if(rockets == -1)
	{
		rockets = 1;
		rocket_id = BigBoomattack;
	}
	
	for(var i=0; i<rockets; ++i)
	{
		var rocket_angle = angle + Random(anglespread) - anglespread/2;
		var rocket_radius = radius * RandomX(80,100) / 100;
		var x =  Sin(rocket_angle, rocket_radius)+LandscapeWidth()/2;
		var y = -Cos(rocket_angle, rocket_radius)+LandscapeHeight()/2;

		CreateObjectAbove(rocket_id, x, y)->Launch(rocket_angle + 180);
	}
	
	for(var i=0; i<GetPlayerCount(); ++i)
	{
		var owner = GetPlayerByIndex(i);
		var gui_arrow = FindObject(Find_ID(GUI_GoalArrow), Find_Owner(owner));
		if(!gui_arrow)
		{
			gui_arrow = CreateObjectAbove(GUI_GoalArrow,0,0,owner);
			gui_arrow->SetAction("Show", GetCursor(owner));
			gui_arrow->SetClrModulation(RGB(255,0,0));
			gui_arrow->SetObjectBlitMode(GFX_BLIT_Mod2);
		}
		gui_arrow->SetR(angle);
		gui_arrow.Plane = 500;
	}
}
Exemplo n.º 26
0
 /*
 *  GLUT calls this toutine when there is nothing else to do
 */
 void idlefunc()
 {
   double t = glutGet(GLUT_ELAPSED_TIME)/1000.0;
   int change = 2.0;
   int lane;
   idle[0] = fmod(90*t,360);
   idle[1] = fmod(45*t,360);
   idle[2] = fmod(30*t,360);
   idle[3] = fmod(22.5*t,360);
   idle[4] = fmod(18*t,360);
   idle[5] = fmod(15*t,360);
   //If rolling
   if(roll < rollmax)
   {
     roll += 1*change;
     ph -= (((6.0*change)*360) / rollmax) ;
     ph %= 360;
     zOffset += ((change*120.0) / rollmax);
     yOffset = 3 - 1.5*Sin(ph);
     explosion[3] += zOffset > 105.0 ? 1.0 : 0.0 ;
     if(zOffset >= 120.0)
     {
       ph = 0;
       zOffset = 0;
       yOffset = 3;
       xOffset = -31.0;
       roll = rollmax;
     }
   }
   for(lane = 0; lane < 8 ; lane++)
   {
     explode_and_reset(lane);
     roll_dat_ball(lane);
   }
   glutPostRedisplay();
 }
Exemplo n.º 27
0
inline void
MakeDiscreteFourier( Matrix<Complex<R> >& A )
{
#ifndef RELEASE
    CallStackEntry entry("MakeDiscreteFourier");
#endif
    typedef Complex<R> F;

    const int m = A.Height();
    const int n = A.Width();
    if( m != n )
        throw std::logic_error("Cannot make a non-square DFT matrix");

    const R pi = 4*Atan( R(1) );
    const F nSqrt = Sqrt( R(n) );
    for( int j=0; j<n; ++j )
    {
        for( int i=0; i<m; ++i )
        {
            const R theta = -2*pi*i*j/n;
            A.Set( i, j, Complex<R>(Cos(theta),Sin(theta))/nSqrt );
        }
    }
}
Exemplo n.º 28
0
void TransformCosSin_Sin(Real a,Real b,Real& c,Real& d)
{
  //use sin(x+d) = sin(x)cos(d) + cos(x)sin(d)
  //=> a=c*sin(d), b=c*cos(d)
  //=> c^2 = a^2+b^2
  if(a==0 && b==0) { c=d=0; }
  else {
    d = Atan2(a,b);
    c = pythag(a,b);
  }
  Real x=0.5;
  if(!FuzzyEquals(c*Sin(x+d),a*Cos(x)+b*Sin(x))) {
    printf("Error in TransformCosSin\n");
    printf("a: %f, b: %f\n",a,b);
    printf("c: %f, d: %f\n",c,d);
    printf("f(x): %f\n",a*Cos(x)+b*Sin(x));
    printf("g(x): %f\n",c*Sin(x+d));
  }
  Assert(FuzzyEquals(c*Sin(x+d),a*Cos(x)+b*Sin(x)));
}
Exemplo n.º 29
0
static void roadsign()
{
   glEnable(GL_TEXTURE_2D);
    glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
   glColor3f(1,1,1);
   glBindTexture(GL_TEXTURE_2D,sky[5]);
   glPushMatrix();
   glBegin(GL_QUADS);
   {
   	glNormal3f(0,0,1);
   	glTexCoord2f(0,1); glVertex3f(-1.5,11.5,0);
   	glTexCoord2f(0,0); glVertex3f(0,10,0);
   	glTexCoord2f(1,0); glVertex3f(1.5,11.5,0);
   	glTexCoord2f(1,1); glVertex3f(0,13,0);
   }
   glEnd();
   glPopMatrix();
   glDisable(GL_TEXTURE_2D);

   glEnable(GL_TEXTURE_2D);
   glColor3f(1,1,1);
   glBindTexture(GL_TEXTURE_2D,texture[2]);
   glPushMatrix();
   glTranslated(0,-1,0);
   glScaled(0.1,11,0.1);
   glBegin(GL_QUAD_STRIP);
   for (th=0;th<=360;th+=15)
   {  glTexCoord2f(Sin(i),0);
      glNormal3f(Cos(th),1,Sin(th));
      glVertex3f(Cos(th),1,Sin(th));
       glTexCoord2f(Sin(i),1);
        glNormal3f(Cos(th),0,Sin(th));
      glVertex3f(Cos(th),0,Sin(th));
   }
   glEnd();
   glPopMatrix();
   glDisable(GL_TEXTURE_2D);
}
Exemplo n.º 30
0
/* Rotates the point (x, y) around (ox, oy) by angle degrees. */
global func Rotate(int angle, int &x, int &y, int ox, int oy, int prec) {
	var xr = Cos(angle, x, prec) - Sin(angle, y, prec),
	    yr = Sin(angle, x, prec) + Cos(angle, y, prec);
	x = xr;
	y = yr;
}