Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problems with rotation and direction  (Read 2667 times)

0 Members and 1 Guest are viewing this topic.

viz_fuerte

  • Newbie
  • *
  • Posts: 4
    • View Profile
Problems with rotation and direction
« on: June 18, 2010, 01:38:16 am »
Hi!
I have a problem that is safe of mathematics , and not of SFML.

I'm doing a game ships(sprite), and bullets do not go according to the rotation of the ship, go up.
If the ship has a rotation of 90 degrees and the bullets too, but do not follow the direction of the ship. The bullets rotate the same but if the ship is moving at x: 10, the bullets continue straight y: 20+
Code: [Select]

CBullet::CBullet(float x,float y,float r,E_BULLET_TYPE t)
{
//# Carga la images
img_bullet.LoadFromFile("media/sprites/bullet.png");
img_bullet.SetSmooth(false);

//# Crea el sprite
spr_bullet.SetImage(img_bullet);

//# Posiciona el sprite
spr_bullet.SetPosition(x,y);

//# Centro del sprite
spr_bullet.SetCenter(spr_bullet.GetSize().x/2.f,
spr_bullet.GetSize().y/2.f);

//# Gira el sprite
spr_bullet.SetRotation(rot);

//# Variables
type = t;
rot = r;
}

void CBullet::Update(bool mov)
{
if(mov)
spr_bullet.Move(-400.f * App.GetFrameTime());

App.Draw(spr_bullet);
}


In other libraries have not had problems doing this, but this is not how.
I've searched the forum but there is no convincing answers.

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Problems with rotation and direction
« Reply #1 on: June 18, 2010, 09:53:42 pm »
It sounds like you need to add the position of the bullet to the ship sprite position.

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Re: Problems with rotation and direction
« Reply #2 on: June 18, 2010, 11:10:27 pm »
Quote from: "viz_fuerte"

Code: [Select]
//# Gira el sprite
spr_bullet.SetRotation(rot);

//# Variables
type = t;
rot = r;


The variable rot is being applied to the sprite rotation before being assigned with the parameter r.
I suggest type and rot to be assigned before the other initializations, or do spr_bullet.SetRotation(r); instead.
By the way, do you really need the variable rot? You can get/set it from the sprite at any time.
Pluma - Plug-in Management Framework

viz_fuerte

  • Newbie
  • *
  • Posts: 4
    • View Profile
Problems with rotation and direction
« Reply #3 on: June 20, 2010, 06:59:59 pm »
The truth, I have always used matrices to make that kind of thing, so the models (referring to 3D environments), rotated and followed a local position and rotation.

It would have to do something to continue the rotation and position local, not global, but it would create a matrix and more, more work.

I lose much by using 2D environments (and that some say is easier).  :lol:

Thanks for the help.  :wink:

 

anything