# Rotating World vertices in the Geometry-Shader

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

## Recommended Posts

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.

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

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.color = colour;
gOut.arrayid = gIn[0].arrayid;
triStream.Append(gOut);
ctr++;
if(ctr >= 4)
{ ctr = 0;
triStream.RestartStrip();
}

##### Share on other sites

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;

[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.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

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 12
• 10
• 13
• 104
• 11
• ### Forum Statistics

• Total Topics
632982
• Total Posts
3009689
• ### Who's Online (See full list)

There are no registered users currently online

×