Rotation help Updated
Rotation help Updated
Hey guys, I'm working on yet another crazy idea of making a Galaga clone. It's in it's early stage and i am trying to get the ship(s) to come onto the the screen and follow a bezier curve. The issue is rotating the sprite, it's not going so well. I was wondering if any of you brainiacs could help me with it. The rotation is in the Player update.
The image is a 32x32 and in it's original state the ship (or simple test image) is pointing upward. If someone could rotate me in the right direction, i'd appreciate that
Peace Out
The image is a 32x32 and in it's original state the ship (or simple test image) is pointing upward. If someone could rotate me in the right direction, i'd appreciate that
Peace Out
- Attachments
-
- Galagaz.zip
- (129.14 KiB) Downloaded 98 times
Last edited by MrGodin on February 12th, 2017, 12:43 am, edited 1 time in total.
Curiosity killed the cat, satisfaction brought him back
Re: Rotation help
well i fixed it by adding 90 degrees with
Code: Select all
// added to Utils
static inline float DegToRad(float angle) { return angle * PI / 180.0f; }
// correction, but i don't like it
angle = velocity.GetAngle() + Utils::DegToRad(90.0f);
Curiosity killed the cat, satisfaction brought him back
Re: Rotation help Updated
Ok, so this is more realistic to how it should go
- Attachments
-
- Galagaz.zip
- (138.32 KiB) Downloaded 109 times
Curiosity killed the cat, satisfaction brought him back
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Rotation help Updated
If it's just 90 degrees you want to turn, and the Z coord stays the same, you can just flip the sign of X and swap the x and y
// Clockwise rotation 90 degrees
velocity = Vec3( velocity.y, -velocity.x, velocity.z )
// CounterClockwise rotation 90 degrees
velocity = Vec3( -velocity.y, velocity.x, velocity.z )
Another way would be to use the CrossProduct between the objects forward vector and and it's up vector. That will give you a 90 degree vector from the forward vector. Though, depending on the order you do the cross product, you'll either get a clockwise or counter clockwise rotation.
// Clockwise rotation 90 degrees
velocity = Vec3( velocity.y, -velocity.x, velocity.z )
// CounterClockwise rotation 90 degrees
velocity = Vec3( -velocity.y, velocity.x, velocity.z )
Another way would be to use the CrossProduct between the objects forward vector and and it's up vector. That will give you a 90 degree vector from the forward vector. Though, depending on the order you do the cross product, you'll either get a clockwise or counter clockwise rotation.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Rotation help Updated
I'm using a Vec2 and put in the vector class a GetAngle function which is atan2(y,x) which returns a good angle (normally) but in this case it doesn't seem to.albinopapa wrote:If it's just 90 degrees you want to turn, and the Z coord stays the same, you can just flip the sign of X and swap the x and y
// Clockwise rotation 90 degrees
velocity = Vec3( velocity.y, -velocity.x, velocity.z )
// CounterClockwise rotation 90 degrees
velocity = Vec3( -velocity.y, velocity.x, velocity.z )
Another way would be to use the CrossProduct between the objects forward vector and and it's up vector. That will give you a 90 degree vector from the forward vector. Though, depending on the order you do the cross product, you'll either get a clockwise or counter clockwise rotation.
I'm also using the Mat3 rotation in the old Thrust series, perhaps the combination of the two is the issue ?
Curiosity killed the cat, satisfaction brought him back
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Rotation help Updated
Ok, so after looking at your code a bit, you need the actual angle in order to do the matrix rotation transformations...well, I guess vectors aren't going to do you much good in that department.
Ha, yeah, just realized that. It seems to look like it's working on the ships that you have, what's the issue?
Ha, yeah, just realized that. It seems to look like it's working on the ships that you have, what's the issue?
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Rotation help Updated
Adding the 90 to the angle retrieved from the Vec2 class. When i used this in Direct2D (the Vec2.GetAngle()) and passed it to the D2D1::Matrix3F::Rotation .. it worked fine. Anyways as you said, i have corrected the issue.Ha, yeah, just realized that. It seems to look like it's working on the ships that you have, what's the issue?
Hmmmm, i watched that series again ,well some of it, and come to think of it i remember seeing something in the "chili done fucked it up" somewhere where he fixed the Mat3, i think ..... lol. anyways, i'll look that over
Curiosity killed the cat, satisfaction brought him back