//--------------------------------- // //--------------------------------- void Matrix4::SetRotation(const RotAxis& rot) { float c = static_cast<float>( DegCos( static_cast<float>( rot.Angle() ) ) ); float s = static_cast<float>( DegSin( static_cast<float>( rot.Angle() ) ) ); float values[16] = { rot.Axis().X() * rot.Axis().X() * ( 1 - c ) + c, rot.Axis().X() * rot.Axis().Y() * ( 1 - c ) + rot.Axis().Z() * s, rot.Axis().X() * rot.Axis().Z() * ( 1 - c ) - rot.Axis().Y() * s, 0, rot.Axis().X() * rot.Axis().Y() * ( 1 - c ) - rot.Axis().Z() * s, rot.Axis().Y() * rot.Axis().Y() * ( 1 - c ) + c, rot.Axis().Y() * rot.Axis().Z() * ( 1 - c ) + rot.Axis().X() * s, 0, rot.Axis().X() * rot.Axis().Z() * ( 1 - c ) + rot.Axis().Y() * s, rot.Axis().Y() * rot.Axis().Z() * ( 1 - c ) - rot.Axis().X() * s, rot.Axis().Z() * rot.Axis().Z() * ( 1 - c ) + c, 0, 0, 0, 0, 1 }; Set( values ); }
void CEnemyStateMoving::Update(double elapsed){ m_timeToShoot += elapsed; double playerX = m_spritePlayer->GetX(); double playerY = m_spritePlayer->GetY(); double enemyX = m_sprite->GetX(); double enemyY = m_sprite->GetY(); double angle = m_sprite->GetAngle(); double distance = Distance(playerX, playerY, enemyX, enemyY); //Giramos al sprite en direccion al contrincante double ux = (playerX - enemyX) / distance; double uy = (playerY - enemyY) / distance; double dot = - ux *DegSin(angle) - uy * DegCos(angle); double angBetweenSprites = DegACos(ux *DegCos(angle) - uy * DegSin(angle)); //Pedimos la velocidad MGetSpeeds gsmsg; m_entity->SendMessage(&gsmsg); //Calculamos hacia donde debe rotar if (!m_sprite->IsRotating()){ if (dot >= 0){ m_sprite->RotateTo((int32)(angle + angBetweenSprites), gsmsg.rotationSpeed); } else{ m_sprite->RotateTo((int32)(angle - angBetweenSprites), gsmsg.rotationSpeed); } } //Avanzamos o retrocedemos manteniendo una distancia de seguridad if (distance < 210){ if (!m_sprite->IsMoving()){ m_sprite->MoveDown(210 - distance, gsmsg.linearSpeed); } } else if (distance > 250) { if (!m_sprite->IsMoving()){ m_sprite->MoveUp(distance - 250, gsmsg.linearSpeed); } } //Cada cierto tiempo dispara una bala if (m_timeToShoot > 2){ m_stateMachine->ChangeState(ESTATE_ENEMY_SHOOTING); m_sprite->SetIsMoving(false); } }
void CMissile::Run() { double x = this->GetX(); double y = this->GetY(); x += m_speed * Screen::Instance().ElapsedTime() * DegCos(m_angle); y += m_speed * Screen::Instance().ElapsedTime() * -DegSin(m_angle); if (x - m_radius <= 0 || x + m_radius >= Screen::Instance().GetWidth() || y - m_radius <= 0 || y + m_radius >= Screen::Instance().GetHeight()) SetDestroy(true); else SetPosition(x, y); }
//Sprite es de la entidad de donde sale la bala void CWeapon1Movement::Init(Sprite* sprite, double vel){ double centerX = sprite->GetX(); double centerY = sprite->GetY(); double angle = sprite->GetAngle(); double width = sprite->GetImage()->GetWidth(); //por la scala si queda grande la bala a su escala original double height = sprite->GetImage()->GetHeight(); //Calculamos el punto desde donde sale el disparo y la direccion 0.4 como offset double initX = centerX + (0 * DegCos(360 - angle + 90) + width * 0.4 * DegSin(360 - angle + 90)); double initY = centerY - (0 * DegSin(angle - 360 - 90) + height * 0.4 * DegCos(360 - angle + 90)); //Cambiamos el punto donde se pintara la bala al iniciarse MGetSprite gsmsg; m_owner->SendMessage(&gsmsg); gsmsg.sprite->SetX(initX); gsmsg.sprite->SetY(initY); gsmsg.sprite->SetAngle(angle); //Inicializamos el movimiento de la bala m_initX = initX; m_initY = initY; m_velocity = vel; m_dirX = initX - centerX; m_dirY = initY - centerY; }
void Renderer::DrawEllipse(double x, double y, double xradius, double yradius) const { GLdouble vertices[ELLIPSEPOINTS*2]; for ( uint32 i = 0; i < ELLIPSEPOINTS; i++ ) { vertices[i*2] = x + (DegCos(i * 360.0 / ELLIPSEPOINTS) * xradius); vertices[i*2+1] = y + (DegSin(i * 360.0 / ELLIPSEPOINTS) * yradius); } GLdouble texCoords[ELLIPSEPOINTS*2]; memset(texCoords, 0, ELLIPSEPOINTS*2*sizeof(GLdouble)); glBindTexture(GL_TEXTURE_2D, 0); glVertexPointer(2, GL_DOUBLE, 0, vertices); glTexCoordPointer(2, GL_DOUBLE, 0, texCoords); glDrawArrays(GL_TRIANGLE_FAN, 0, ELLIPSEPOINTS); }
ITreeNode::TResult CalculateAvoidanceDestiny::Run() { Entity * enemy; context->GetValueEntity(TreeContext::KEY_THREAT, &enemy); Vec2D direction, threat; float projection; direction.x = DegCos(owner->rotation - 90)*linearSpeed; direction.y = DegSin(owner->rotation - 90)*-linearSpeed; threat.x = enemy->x - owner->x; threat.y = enemy->y - owner->y; projection=threat.Dot(direction); direction.normalize(); return TResult(); }