• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Basic movement (with shapes)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1Inuyashakagome16  Members

Posted 15 January 2013 - 11:34 AM

I'm having an issue with moving a shape around the screen using the keyboard.

http://pastebin.com/GLCj5Q5w < that is all I have thus far. It's a bit of a mess because I'm attempting to figure out what I'm doing wrong.

I understand how shapes are displayed on the screen but I don't understand how to move them.

Do I move the coordinates around? Or does the camera have to move around?

I apologize for not displaying much code here except for what's in the pastebin. I just can't seem to find much info regarding this / I don't know where to look and it's frustrating to an extent.

EDIT: A few minutes of http://simplynoise.com/ seemed to help. -.-

Still can't figure it out but what I had been trying is updating the camera. (Or what parts of it I had implemented)

I thought (and still do) that because I'm moving something IN the game that really its not moving but rather the camera is.

Main Goal: Move Shape, then put in textures and collision and have shape move along textures. (you can see where this is going)

Very simple goal, but i'm stuck here.

Edited by Inuyashakagome16, 15 January 2013 - 11:48 AM.

### #2HAM  Members

Posted 15 January 2013 - 12:09 PM

You can do either one. But what you are probably failing to understand is that all the drawing occurs with a single matrix. In your code you'll probably find somewhere that multiplies three matrices together:

World * view * projection

All three get multiplied together producing a single matrix that every vert is multiplied by.

Typically you will use this terminology, and three separate matrices, because its pretty standard and helps you mentally keep separate the object position, camera position, and projection. But it doesn't really matter if you change the world or view matrix to draw an object in a different place on the screen. Because what matters is the final matrix the vert gets multiplied with. There is always a way to modify either the world or view matrix to produce the same result.

But usually if you are wanting to move an object, then you store a position ( a single 3d vector) for it, and move that position around. When it comes to drawing the object you then setup the world matrix to translate the objects position.

If you are wanting to move a camera around, then you normally store a camera position and move it around. When it comes time to drawing you setup the view matrix to translate the camera position.

That is the basic idea. There is a ton of little details and honestly you can do it any way you want, as long as that final matrix you multiply every vert by gets those verts into the position you want.

I would recommend Fletcher Dunn's 3D game math book if you are confused about the matrices and verts and how those end up deciding what gets on the screen.

### #3Inuyashakagome16  Members

Posted 15 January 2013 - 12:33 PM

void UpdateScene(double time)
{
World = XMMatrixIdentity();

Scale = XMMatrixScaling(500.0, 10.0f, 500.0f);

Translation = XMMatrixTranslation(0.0f, 10.0f, 0.0f);

World = Scale * Translation;
}

void DrawScene()
{
D3DXCOLOR bgColor(0.0f, 0.0f, 1.0f, 0.0f);

d3d11DevCon->ClearRenderTargetView(renderTargetView, bgColor);

World = XMMatrixIdentity();

WVP = World * camView * camProjection;

cbPerObj.WVP = XMMatrixTranspose(WVP);

d3d11DevCon->UpdateSubresource(cbPerObjectBuffer, 0, NULL, &cbPerObj, 0, 0);

d3d11DevCon->VSSetConstantBuffers(0, 1, &cbPerObjectBuffer);

d3d11DevCon->Draw(3,0);

SwapChain->Present(0,0);
}

Like that pretty much.

I understand where they all need to be multiplied for you to have the correct output. I guess I was just missing where I needed to use the stored value. (I'm really not sure why I don't completely understand this)

        Vertex v[] =
{
Vertex(0.0f, 0.5f, 0.5f),
Vertex(0.5f, -0.5f, 0.5f),
Vertex(-1.0f, -0.5f, 0.5f),
};

Is where I had the values for what was to be displayed. Are you talking about the v[] ? Because it is stored there.

And then there is the Update. >_>

void Update()
{
XMMATRIX anew;
anew = XMMatrixIdentity();

camTarget = XMVector3Normalize(camTarget);

camUp = XMVector3TransformCoord(camUp, anew);
camForward = XMVector3TransformCoord(DefaultForward, anew);

camPosition += moveUpDown*camForward;
moveUpDown = 0.0f;

camTarget = camPosition + camTarget;

camView = XMMatrixLookAtLH(camPosition, camTarget, camUp);
}

Which is where I just started trying different things without stopping to think about what I'm trying to do.

i'm probably going to have to look that book up as well. I have a decent understanding its just somethings here are a bit tough (at first.)

The overall goal here was just to display something, move it around, setup collision (as stated before) and have the camera follow me. At that point i thought well i have to just move around the object instead. I'm guessing I just have to reread a few chapters because i must have missed something.

### #4HAM  Members

Posted 15 January 2013 - 12:46 PM

In the UpdateScene the Translation matrix is going to change your objects posiiton.

In this case your three verts:

(0.0f, 0.5f, 0.5f)

(0.5f, -0.5f, 0.5f)

(-1.0f, -0.5f, 0.5f)

get translated by (0, 10, 0) and become

(0.0f, 10.5, 0.5)

(0.5f, 9.5f, 0.5f)

(-1.0f, 9.5f, 0.5f)

So if you want to move your object around just store a Vertex for its position:

Vertex currentPosition;

Translation = XMMatrixTranslation(currentPosition.x, currentPosition.y, currentPosition.z);

And now you control where those verts get drawn by changing the variable 'currentPosition'.

Edited by HAM, 15 January 2013 - 12:47 PM.

### #5Trienco  Members

Posted 15 January 2013 - 11:31 PM

This sounds more like a basic misunderstanding how this works. You don't draw stuff and then move it around. Every frame you draw everything from scratch with the position it is supposed to be at.

Don't expect this work like a GUI, where you can just place and move objects around.

f@dzhttp://festini.device-zero.de

### #6Inuyashakagome16  Members

Posted 16 January 2013 - 04:48 AM

This sounds more like a basic misunderstanding how this works. You don't draw stuff and then move it around. Every frame you draw everything from scratch with the position it is supposed to be at.

Don't expect this work like a GUI, where you can just place and move objects around.

i'm aware it doesn't work like a GUI. I have the concept where each "frame" or iteration you can change a value and more around an object. However I couldn't figure out how to do it at first.

### #7HAM  Members

Posted 16 January 2013 - 07:55 AM

If what I said didn't make sense, let me know and I'll try to be more clear.   Otherwise, good luck.  I bet you've got it by now.

### #8Inuyashakagome16  Members

Posted 16 January 2013 - 08:10 AM

It does it just took a second. I do thank you for your help. It seems that when learning the "World, View Projection and Transformations" I forgot to read a few paragraphs so I knew the syntax just not the theory. So i'm going back over it now and it's starting to click. When I do figure it out i'll post and explain what I think it is, just for the record.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.