Sign in to follow this  
TriML

Container for shape manipulation

Recommended Posts

TriML    124
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 this post


Link to post
Share on other sites
cannonicus    136
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 this post


Link to post
Share on other sites
TriML    124
Quote:
Original post by cannonicus
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


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 this post


Link to post
Share on other sites
cannonicus    136
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 center
0.0f, //Scaling rotation factor (not sure what this does)
&scaling, //scaling
&D3DXVECTOR2(0,0), //Rotation center
angle, //Rotation
&translation //translation
);

for(int i=0; i<nr_verts; i++)
{
D3DXVECTOR4 tmp;
D3DXVec2Transform(
&tmp, //output vertex
&verts[i], //input vertex
&transform //transformation matrix
);

//Go back to 2D
verts[i].x = tmp.x;
verts[i].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 this post


Link to post
Share on other sites
TriML    124
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this