MikeyBe Posted August 10, 2004 Posted August 10, 2004 Goal: I'm trying to make a game similar to the 2D atari classic "Tank" where 2 tanks move around the screen and try to shoot each other. I'm pretty new to this stuff. I have suceeded in making the tanks using position vertices (which I am thinking now after reading some posts, is a bad idea) and am now trying to create matrices to move the tanks around since I want to use direction and vectors to move the tanks vs. having to move them pixels at a time by calculating slopes etc. I made the tanks using a trianglelist and put them on the screen using pixel coordinates(i.e positionvertex). However, I don't know how to associate a matrix with my tank. I assume that I need to use transform matrices to draw the tanks, but have only seen posts on how to transform the world, or camera etc. which will, as I understand it, move both of my tanks. I want to know how to move 1 tank without moving the other. I'm leaving this somewhat vague on purpose so that someone might feel kind enough to give me some insight on the best methods to make this type of game. A brief primer on what the transform matrix coordinates mean would be helpful as well (I notice that they are numbers like 0,1,1 as opposed to screen pixel coordinates. Thanks, MikeyBe Quote
rifter1818 Posted August 11, 2004 Posted August 11, 2004 (edited) Goal: I'm trying to make a game similar to the 2D atari classic "Tank" where 2 tanks move around the screen and try to shoot each other. I'm pretty new to this stuff. I have suceeded in making the tanks using position vertices (which I am thinking now after reading some posts, is a bad idea) and am now trying to create matrices to move the tanks around since I want to use direction and vectors to move the tanks vs. having to move them pixels at a time by calculating slopes etc. I made the tanks using a trianglelist and put them on the screen using pixel coordinates(i.e positionvertex). However, I don't know how to associate a matrix with my tank. I assume that I need to use transform matrices to draw the tanks, but have only seen posts on how to transform the world, or camera etc. which will, as I understand it, move both of my tanks. I want to know how to move 1 tank without moving the other. I'm leaving this somewhat vague on purpose so that someone might feel kind enough to give me some insight on the best methods to make this type of game. A brief primer on what the transform matrix coordinates mean would be helpful as well (I notice that they are numbers like 0,1,1 as opposed to screen pixel coordinates. Thanks, MikeyBe If your going to be doing it purly in 2d it might be easier to use a sprite to render textures instead of a Vertex Array, However your question pertains to said array so ill see what i can do to help you there, most of the graphics i use Directx for are fully 3d So here is my suggestion to you, You should only need 1 Vertex Array for all the tanks (assuming they all look the same) then just have different colors or textures to tell them appart (easy part). Now the way i do my tranformations is as follows, Simply Translate the world matrix to what you want device.transforms.world=Matrix.Multiply(RotationMatrix,TranslationMatrix); Render that object and then transform the world to the next object and render that one, You might want to play around with the multiplication thinking about it maybe its supposed to be the other way around (Translation * Rotation) but thats a miniscule point. The important part is that changing the world matrix doesnt effect anything that has been rendered only what you are rendering (with the current world matrix). Anyways thats my suggestion for your question hope this helps. Edit Almost forgot the other part to your question. All the corrordinants are in Units (general) how many pixels each is depends on your Viewport and projection etc, the easiest way to picture it for me is like a camera, 1 unit could be 10 pixels but if you zoomed in it could be 50 pixels so its really all relative. The best thing for you to do i think before you start on the game is just play around with 1 or 2 objects and the "camera" until you get used to it (assuming you are using 3d) The "camera" is adusted by using Matrix.LookAtLH() or Matrix.LookAtRH() as your view matrix, the Projection Matrix can then be thought of as the type of lense you use, you can set Near and Far clip plains and the View Angle (which if you are crafty with it can be used for creating a zoom lense like effect). Then i guess comes the options of whether you move all the objects and leave the camera stationary, or move the Camera.... Oh yes and ill randomly through this in, to get from Screen Space to World space and back you use Vector3.Project() and Vector3.UnProject() which can be a little tricky, at first but once you get used to them its easy as pi. I guess all of Directx is like that really, leaving only the question how easy is pi? Edited August 11, 2004 by rifter1818 Quote
ThePentiumGuy Posted August 11, 2004 Posted August 11, 2004 I want to know how to move 1 tank without moving the other. Heh heh! This is the very same question that I struggled with when I first started out doing some Direct3D. Well you know how you have to move the world in order to move the object, right? Now throw in 2 objects - you have 2 tanks for example. Both tanks want to go right 2 pixels - so you translate the world to the right byt2 pixels. Now lets say you want to have one tank go left, and one tank go right. Here's what you'd do --- dxdevice.transform.world = matrix.identity 'All this does it sets the world to its default position (meaning 0,0,0 is the center) dxdevice.transform.world = matrix.translation(2,0,0) 'move the world right tank1.render 'render the tank to the right of its previous position dxdevice.transform.world = matrix.identity 'Sets the world back to its default position - now remember, even though you've set the world back to default (meaning you moved it left 2) tank1 wont move left 2 units - this is becuase you've already rendered it, so it "stays" there at position 2,0,0.. get what i mean? dxdevice.transform.world = matrix.translation(-2,0,0) tank2.render 'render the tank 2 units to the left of where it was before. --- You must be wondering why we keep translating the world back to the identity - lets say you do this d3ddev.transform.world = matirx.translation(2,0,0) tank1.render d3ddev.transform.world = matrix.translation (-2,0,0) tank2.render where would tank 2 render? it would render in position (0,0,0) ... to avoid this, you just simply translate the world to 0,0,0 ;) (meaning set it to identity) get what i mean? --- now to answer the 2nd part of your question: assigning matrices for each tank well, its kind of easy.. in your clsTank or whatever sprite class you made, assign positions for each tank Public pos as vector3 and when you push right for example pos.x += 2... ..etc do this for all the directions now about the matrices, Public Readonly Property mTankPosition as Matrix.Translation Get Return New Matrix.Translation(pos) End Get End Property so basically your code would look like this when you translate the wolrd dxdevice.transform.world = tank1.mTankPosition get what i mean? I hope this helps, if you want i can go into more details beucase this is a tricky concept i must admit pent Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
MikeyBe Posted August 11, 2004 Author Posted August 11, 2004 Wow what great answers from both of you! Exactly what I wanted to know! I will play for the next few days and see what I come up with:) Thanks so much! Mike Quote
rifter1818 Posted August 12, 2004 Posted August 12, 2004 Pent? Are you Sure about this? World = Matrix.Translation(2,0,0); World = Matrix.Translation(-2,0,0); Leaves it at (0,0,0)? I thought it would leave it at (-2,0,0) but i guess it shows you learn every day. Oh well just my $0.02 worth, and by the way nice responce you nailed the question better than i did, oh well. Quote
ThePentiumGuy Posted August 13, 2004 Posted August 13, 2004 Actually man, you're right. It does translate to -2,0,0. Sorry about that :). World = Matrix.Multiply(World, Matrix.Translation(-2,0,0)) would set it to 0,0,0. Heh, thanks for letting me know :). -The Pentium Guy Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.