Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post Posted: September 13th, 2017, 5:28 am 
 

Joined: September 7th, 2014, 3:45 am
Posts: 15
After a lot of googling and Youtube I am lost on how to make a 2D image rotate. It seems to more I search the more confused I get lol I am attaching a simple project where I have a triangle drawn on the screen. For the sake of argument we will pretend that the triangle is a "ship". I have draw 2 sides of the triangle a different color to indicate the front of the ship. Can anybody help me with making my ship rotate?

For instance lets say I want the ship to point towards the mouse cursor.


Attachments:
NewGame.zip [5.13 MiB]
Downloaded 10 times
Top 
 Profile  
Reply with quote  
 Post Posted: September 14th, 2017, 4:22 am 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3468
Location: Japan
Can't download right now. Are you trying to rotate a raster image, or just a triangle drawn with lines? If it is the latter, then it's pretty easy my friend.

Check out my Advanced Tutorial 3 for a thorough explanation about rotation math.

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post Posted: September 14th, 2017, 6:07 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2827
Location: Oklahoma, United States
Yeah, it's going to be best to understand matrix transformations if you ever want to move on to 3D.

I added a matrix class and a Vec3 class to your project. I changed the Vec2 class to a template class and renamed the GetNormalized to Normalize, but those were just for my sanity.

The ship now points at the mouse cursor, check out the Ship::Draw function for the matrix stuff.

I used vector math to get the direction from ship to mouse pointer in Ship::Update, then I use atan2f in the draw function to get the angle.


Attachments:
NewGame_Rotations.zip [564.85 KiB]
Downloaded 5 times

_________________
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
Top 
 Profile  
Reply with quote  
 Post Posted: September 15th, 2017, 1:34 am 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3468
Location: Japan
Matrix stuff is definitely required learning, but I would not recommend starting with them. There is nothing about matrices or rotation that obliges you to use them together. One problem at a time.

First learn how to do rotation math with in simple C++ statements. Once you have your head around that, then you can study matrices, study how they can be used to encode and concatenate transformations, and apply that tech to rotation / scaling.

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post Posted: September 15th, 2017, 5:35 am 
 

Joined: September 7th, 2014, 3:45 am
Posts: 15
Yes its just a triangle with a draw line function. I will definitely check out that tutorial chili. Most things I have found online haven't really explained it well


Top 
 Profile  
Reply with quote  
 Post Posted: September 15th, 2017, 5:37 am 
 

Joined: September 7th, 2014, 3:45 am
Posts: 15
albinopapa wrote:
Yeah, it's going to be best to understand matrix transformations if you ever want to move on to 3D.

I added a matrix class and a Vec3 class to your project. I changed the Vec2 class to a template class and renamed the GetNormalized to Normalize, but those were just for my sanity.

The ship now points at the mouse cursor, check out the Ship::Draw function for the matrix stuff.

I used vector math to get the direction from ship to mouse pointer in Ship::Update, then I use atan2f in the draw function to get the angle.


A lot of what you said may as well be in Spanish lol


Top 
 Profile  
Reply with quote  
 Post Posted: September 15th, 2017, 5:55 am 
 

Joined: September 7th, 2014, 3:45 am
Posts: 15
@albinopapa what you did works great and that is exactly what I was looking for. I've been over looking you code and I am having trouble understanding exactly what is happening. So I am going to check out Chili's advanced tutorials to try to understand this stuff better.


Top 
 Profile  
Reply with quote  
 Post Posted: September 15th, 2017, 6:27 am 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3468
Location: Japan
Walka wrote:
@albinopapa what you did works great and that is exactly what I was looking for. I've been over looking you code and I am having trouble understanding exactly what is happening. So I am going to check out Chili's advanced tutorials to try to understand this stuff better.


Right on. If you're doing line drawing it will be easy going I think. Watch A3 and hit me up here or on the Discord if you need clarification on anything. I think A4 or A5 goes over matrices.

We might be able to give you links to some other vids as well on rotation stuff as well as matrix/linear algebra stuff.

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post Posted: September 15th, 2017, 6:29 am 
 

Joined: September 7th, 2014, 3:45 am
Posts: 15
I will check it out soon, I am currently grinding out Destiny 2 ;) Thanks for the help


Top 
 Profile  
Reply with quote  
 Post Posted: September 15th, 2017, 3:39 pm 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3468
Location: Japan
Check your PMs ;)

_________________
Chili


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 10 posts ] 

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: