BJohansson

Hello,

I have a cylinder (standard Primitives) made in 3dmax exported as a *.fbx file.

My question is that I would like to scale or resize the height or radius of the *.fbx (mesh) in realtime later.

Sometimes i would only want to adjust the radius and sometimes only the height.

For every update a variable that is holding the value for the height would be read and feed into the height of the mesh.

Is there any simple ways of doing this

Regards

BJ



Re: XNA Game Studio Express Scaling a mesh or primitives object

Pange

It's all controlled by your World matrix.

if your position is {x,y,z} and your scale is {sx,sy,sz} then use this:

Matrix World = Matrix.CreateTranslation(x, y, z) * Matrix.CreateScale(sx, sy, sz);

you can also multiply-in rotations here using Matrix.CreateRotationX(rx) etc





Re: XNA Game Studio Express Scaling a mesh or primitives object

jnog

Sure. Just take a matrix that scales your mesh when applying the transformations to it just before drawing.

Assuming your cylinder's base is placed on the XZ plane and its height follows the Y axis, the scale matrix may be build as such:

float radiusScalingAmount = 1.5; // The amount to scale the radius
float heightScalingAmount = 0.5; // The amount to scale the height

Matrix scaleMat = Matrix.CreateScale( radiusScalingAmount, // X
heightScalingAmount, // Y
radiusScalingAmount ); // Z

Now use that matrix when calculating your final transform matrix for the cylinder, something like (adapted from the 1st tutorial):

protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

//Copy any parent transforms
Matrix[] transforms = new Matrix[myModel.Bones.Count];
myModel.CopyAbsoluteBoneTransformsTo(transforms);

//Draw the model, a model can have multiple meshes, so loop
foreach (ModelMesh mesh in myModel.Meshes)
{
//This is where the mesh orientation is set, as well as our camera and projection
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.World = transforms[mesh.ParentBone.Index] *
scaleMat
*
Matrix.CreateRotationY(modelRotation) *
Matrix.CreateTranslation(modelPosition);

effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
aspectRatio, 1.0f, 10000.0f);
}
//Draw the mesh, will use the effects set above.
mesh.Draw();
}
}









Re: XNA Game Studio Express Scaling a mesh or primitives object

BJohansson

Thank's a bunch for all the help guys! Fast to :)

Now i got something to try out!





Re: XNA Game Studio Express Scaling a mesh or primitives object

BJohansson

Everything worked well guys!

Thanks again!

BJ