Rotation help Updated

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Rotation help Updated

Post by MrGodin » February 11th, 2017, 9:51 pm

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 :P
Peace Out
Attachments
Galagaz.zip
(129.14 KiB) Downloaded 96 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

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: Rotation help

Post by MrGodin » February 11th, 2017, 11:51 pm

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

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: Rotation help Updated

Post by MrGodin » February 12th, 2017, 12:44 am

Ok, so this is more realistic to how it should go
Attachments
Galagaz.zip
(138.32 KiB) Downloaded 105 times
Curiosity killed the cat, satisfaction brought him back

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Rotation help Updated

Post by albinopapa » February 12th, 2017, 1:21 am

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.
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

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: Rotation help Updated

Post by MrGodin » February 12th, 2017, 1:25 am

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 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.
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

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Rotation help Updated

Post by albinopapa » February 12th, 2017, 1:34 am

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?
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

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: Rotation help Updated

Post by MrGodin » February 12th, 2017, 1:41 am

Ha, yeah, just realized that. It seems to look like it's working on the ships that you have, what's the issue?
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.
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

Post Reply