Rotating World vertices in the Geometry-Shader

Started by
0 comments, last by ankhd 11 years, 2 months ago

I'm having trouble rotating vertices that are defined in 3d world space in hlsl code.
Here is what Im trying to do.
Im making vertices on the GS that will form the shape of a round corrner rectangle.
I first create a lobster back bent shape for the right corrner plotting each vertex based
on a outer radius and a inner radius and it has 4 section that form the bend.
I then use these points and the passed in world for the top left side of the round rectangle
to off set the first bend to all other bends to form four corrners.
Now this all works fine up till I want to rotate the whole rectanle 45 degrees on the z axis.
It looks like it rotates about some other axis and move the box all over the place.

How should I go about rotating these verftices or how do I convert them to a object space knowing that there formed only in world space


Oh and I want to rotate about the position that is passed into the shader.

heres a image of what Im talking about for the shape.

HealthBar.jpg?psid=1


this is some of the code that creates the offset vertices
there all like this but offset to there correct locations


//second lobster back section Defined in world space
v[52] = float4(pos.x, pos.y - (innercorrnerpoints[2].y + gIn[0].lengthVertical), pos.z + innercorrnerpoints[2].z + gIn[0].lengthHorizontal, 1.0f);
v[53] = float4(pos.x, pos.y - (outercorrnerpoints[2].y + gIn[0].lengthVertical), pos.z + outercorrnerpoints[2].z + gIn[0].lengthHorizontal, 1.0);
v[54] = float4(pos.x, pos.y - (innercorrnerpoints[1].y + gIn[0].lengthVertical), pos.z + innercorrnerpoints[1].z + gIn[0].lengthHorizontal, 1.0f);
v[55] = float4(pos.x, pos.y - (outercorrnerpoints[1].y + gIn[0].lengthVertical), pos.z + outercorrnerpoints[1].z + gIn[0].lengthHorizontal, 1.0f);

I create this rotation in the shader for rotating the rectangle


float r = radians(gIn[0].rotationZ);
float4x4 rotateZ = { cos(r), -sin(r), 0.0, 0.0,
sin(r), cos(r), 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0 };


this is how its used
ctr = 0;
[unroll]
for(int i = 0; i < 88; i++)
{
m = mul(rotateZ,v );//Rotate here
gOut.posH = mul(m, VP);
gOut.texC = gQuadTexC[ctr];
gOut.color = colour;
gOut.arrayid = gIn[0].arrayid;
triStream.Append(gOut);
ctr++;
if(ctr >= 4)
{ ctr = 0;
triStream.RestartStrip();
}


}

Advertisement

OK fixed it now my health bars follow the units and they are rotated 45 degrees.

I set the pos to 0,0,0

then did the off set calculations and here I created a translation matrix with the real position

float4 m;

pos = gIn[0].initialPosW;//reset the world

float4x4 translate = { 1.0, 0.0, 0.0, 0.0,

0.0, 1.0, 0.0, 0.0,

0.0, 0.0, 1.0, 0.0,

pos.x, pos.y, pos.z, 1.0};


GS_OUT gOut;


int ctr = 0;


//need to add the background quad first then the health bar


[unroll]

for(int i = 0; i < 88; i++)

{

m = mul(rotateZ,v );//Rotate here

m = mul(m,translate);//translate here

gOut.posH = mul(m, WVP);

gOut.texC = gQuadTexC[ctr];

gOut.color = colour;

gOut.arrayid = gIn[0].arrayid;

triStream.Append(gOut);

ctr++;

if(ctr >= 4)

{ ctr = 0;

triStream.RestartStrip();//this is the left side quad start new lot

}

}

//and what it looks like

HealthBoxFixed.jpg?psid=1

This topic is closed to new replies.

Advertisement