# using matrices in 2d -rhw

This topic is 5406 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I've just been testing out some 2d quads and was wondering how to use matrices to rotate them. I realise the XYZRHW FVF means the vertices are already transformed, but I thought maybe you could apply a matrix before filling the vertex buffer, ie applying it diretly to the vertex struct, so, [code/] D3DMATRIX *QuadMatrix; QuadVertex = {{1.0f, 1.0f, etc ....}}// fill in the Vertex struct float *RotationAngle; float GetRotationAngle(float *RotAngle); // input/get an angle & return to RotationAngle. D3DMatrixRotationY(&QuadMatrix, &RotationAngle);//transform the matrix //apply matrix results to the x & y vertices. QaudVertex[0].x = QuadMatrix-> _22; //which matrix values? QaudVertex[0].y = QuadMatrix-> _23; //which matrix values? QaudVertex[1].x = QuadMatrix-> _22; QaudVertex[1].y = QuadMatrix-> _23; QaudVertex[2].x = QuadMatrix-> _22; QaudVertex[2].y = QuadMatrix-> _23; QaudVertex[3].x = QuadMatrix-> _22; QaudVertex[3].y = QuadMatrix-> _23;  After this you would do the rest as normal, is this ok? Would I need to use D3DMatrixRotationX as well and use for the x values? Another thing I wanted to know is are the sin & cosine functions built into the matrix or the D3D matrix function, as in D3DMatrixRotationY etc. Thanks for any help or insight. edit Ah I just saw D3DXMatrixTransformation2D in another post, this might be ok, can this be used with xyzrhw though? I wanted to stick to rhw at the moment [Edited by - Stevieboy on September 27, 2004 7:04:34 PM] 
 0 
 Share this post Link to post Share on other sites 
 
 
 Advertisement Supernat02    604 Supernat02 Member 604 Posted September 27, 2004 Nope it can't be used with RHW. You still have to modulate each vertex. You're on the right track though. You can use D3DXMatrixTransformation2D to create the matrix. Then just multiply the matrix by each vertex. It's simple matrix math, so don't try to make it too complicated.[x', y', z', 1] = [x, y, z, 1] * [Matrix]where Matrix is defined with _RC (row column) elements.So,x' = x*Matrix._11 + y*Matrix._21 + z*Matrix._31 + 1*Matrix._41;y' = x*Matrix._12 + y*Matrix._22 + z*Matrix._32 + 1*Matrix._42;z' = x*Matrix._13 + y*Matrix._23 + z*Matrix._33 + 1*Matrix._43;1 better equal 1;If you check that out, you can see the last term goes to 0 for x', y', and z'. So, just use the first three terms.You'll be rotating around the z-axis, so the matrix will look as follows:[ cos(theta) sin(theta) 0 0 ][ -sin(theta) cos(theta) 0 0 ][ 0 0 1 0 ][ 0 0 0 1 ]As you can see, z' will be z since column 3 has 0's for x and y. I think I've done this right, but I'm sure it will be corrected if not. :)Good luck,Chris 0 Share this post Link to post Share on other sites 
 Sign in to follow this   Followers 0 
 Go To Topic Listing Graphics and GPU Programming googletag.cmd.push(function() { googletag.display('div-gpt-ad-1555502746360-0'); }); Advertisement 
 googletag.cmd.push(function() { googletag.display('div-gpt-ad-1555502640120-0'); }); Advertisement Popular Tags 2D 3D Advice Algorithm C# C++ Concept Design DX11 Feedback Gameplay General Godot Graphics Isometric Marketing Mobile OpenGL Open Source PC Pixel Publishing Unity Unreal VR Popular Now 21 Two weeks until "release" and almost no one knows my game... By MagoganStarted Sunday at 11:41 PM 13 Gameplay Increasing Ram of the System by playing the game continuously By GauttiStarted Sunday at 06:19 AM 9 OpenGL Problem with assimp, some uv's on some meshes are incorrect By Charlie MalmqvistStarted Saturday at 07:04 PM 17 Centering a Ball on the Screen By JosheirStarted Saturday at 03:11 PM 13 How math is used in game development? By Zeus JamesStarted Saturday at 07:16 AM googletag.cmd.push(function() { googletag.display('div-gpt-ad-1555502515948-0'); }); Advertisement GameDev.net GameDev.net Articles GameDev.net Event Coverage GameDev.net Forums GameDev.net Blogs GameDev.net Gallery GameDev.net News GameDev.net Projects GDNet Chat All Activity Search In Everywhere This Forum This Topic More options... Find results that contain... All of my search term words Any of my search term words Find results in... Content titles and body Content titles only Home Forums Programming Graphics and GPU Programming using matrices in 2d -rhw 
 
 
 × Existing user? Sign In Sign Up Browse Back Articles & Tutorials Back All Categories Audio Business Game Design Industry Programming Visual Arts Columns Back GameDev Unboxed Event Coverage Back All Events Game Developers Conference Power Up Digital Games Conference GameDev.Market Links News Podcasts Back All Podcasts Game Dev Loadout Archive Community Back Beginners Back Beginners Group Beginners Forum Beginners Resources Blogs Calendar Chat Forums Back All Forums Audio Business Game Design Programming Visual Arts Community GameDev Challenges Affiliates Topical Workshops Gallery Groups Back For Beginners GameDev Challenges All Groups Projects Back All Projects Games Game Assets Game Mods Developer Tools Store Forums Back All Forums For Beginners Audio Back Music and Sound FX Games Career Development Business Back Games Career Development Production and Management Games Business and Law Game Design Back Game Design and Theory Writing for Games Programming Back Artificial Intelligence Engines and Middleware General and Gameplay Programming Graphics and GPU Programming Math and Physics Networking and Multiplayer Visual Arts Back 2D and 3D Art Critique and Feedback Community Back GameDev Challenges GDNet Lounge GDNet Comments, Suggestions, and Ideas Coding Horrors Your Announcements Hobby Project Classifieds Indie Showcase Affiliates Back NeHe Productions AngelCode Topical Workshops Careers Back Contractors Hobby Projects Game Jobs Back Browse on GameDev.Jobs Post a Job Members Back Subscriptions Chat Guidelines Leaderboard Online Users Awards Search Back All Activity My Activity Streams Back Latest Topics Featured Blogs Search Important Information By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.   I accept GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry. Sign me up! $(document).ready(function() { /* setInterval(function() { //window.googletag.pubads().refresh(); pbjs.que.push(() => { pbjs.setConfig({ bidderTimeout: PBJS_TIMEOUT, useBidCache: true, userSync: { filterSettings: { iframe: { bidders: '*', filter: 'include', }, }, }, }); pbjs.addAdUnits(window.pbjsAdUnits); pbjs.requestBids({ bidsBackHandler: function() { googletag.cmd.push(() => { if (window.pbjs && pbjs.setTargetingForGPTAsync) { pbjs.setTargetingForGPTAsync(); } googletag.pubads().refresh(); }); }, }); }); }, 30000);*/ }); googletag.cmd.push(function() { googletag.display('div-gpt-ad-1555502884201-0'); });$(document).ready(function() { if (ipsSettings.memberID > 0) { ga('send','event','User','Member'); ga('send',{ hitType: 'event', eventCategory: 'User', eventAction: 'Member', eventLabel: ipsSettings.memberID.toString() }); } else { ga('send','event','User','Guest'); } });