# Container for shape manipulation

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

## Recommended Posts

I have drawn different shapes using only lines. Now i want to have control on such things like shape rotation, scaling or like. How do the container for such shapes can be implemented? Any idea? Thanx

##### Share on other sites
A standard vertex-buffer will do the trick if i understand you right. Just place the vertices that build up the lines in a big array. Vertex manipulation is often implemented using different matrices (google has alot of info about matrices).

//emil

##### Share on other sites
Quote:
 Original post by cannonicusA standard vertex-buffer will do the trick if i understand you right. Just place the vertices that build up the lines in a big array. Vertex manipulation is often implemented using different matrices (google has alot of info about matrices).//emil

Yes, i have store all the vertices in an D3DXVECTOR2 array then using ID3DXLine to draw lines. Can u explain a little how the vertex buffer can solve the problem? Thanx a lot.

##### Share on other sites
An array of D3DXVECTOR2 _is_ a vertexbuffer, sort of. If you want your vertexbuffer to take advantage of DirectX hardware accelerated transformation and rendering you will however need to do the vertexbuffer the way directx wants it.

If that isnt necessary an array of vectors is just the thing you need. To transform the shape just multiply each vertex with the proper transformation matrix

Sample:

D3DXVECTOR2 scaling;float angle;D3DXVECTOR2 translation;D3DXMATRIX transform;D3DXMATRIXTransformation2D(&transform, //output matrix&D3DXVECTOR2(0,0), //scaling center0.0f, //Scaling rotation factor (not sure what this does)&scaling, //scaling &D3DXVECTOR2(0,0), //Rotation centerangle, //Rotation&translation  //translation);for(int i=0; i<nr_verts; i++){D3DXVECTOR4 tmp;D3DXVec2Transform(&tmp, //output vertex &verts, //input vertex&transform  //transformation matrix);//Go back to 2Dverts.x = tmp.x;verts.y = tmp.y;}/*Render as usual*/

That code should (i havent tried this particular code snippet) rotate the shape "angle" radians around the zero vector (origo), scale the shape as described in "scaling" also with the zero vector as centrum, and move the whole thing as described in "translation". Play around with the different values and youll get the idea.

Hope it makes sense :)

//Emil

Edit:

You will need to include d3dx9.h and link d3dx9.lib (i think)

[Edited by - cannonicus on November 24, 2005 8:40:26 PM]

##### Share on other sites
Thanx a lot "cannonicus" :) for your help.

I got the idea. Now i m trying to define some proper container like a reasonable rectangle based upon some screen size whose width and height i could use to transform these shapes.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 14
• 12
• 29
• 11
• 44
• ### Forum Statistics

• Total Topics
634856
• Total Posts
3019661
×