Advice on applying this to XNA

Started by
3 comments, last by blewisjr 12 years, 11 months ago
http://freespace.vir...ls/m_landsp.htm

Ive made a sphere in Wings3d, how would i go about applying this technique in XNA?

Very general sort of question i know, but im looking at how i can use xna to modify models, and basically get on my way to create 'planets'.
Thanks for any help!






loop n = random vector ; see method above
loop through each vertex of the sphere d = dotproduct( n , this vertex) ; is this vertex infront of
; or behind the plane?
if d > 0 then ; if infront then
move this vertex out a little bit else ; if behind then
move this vertex in a little bit
end if
end loop



[font="arial, verdana, tahoma, sans-serif"]
[/font]
Advertisement
Wings3D is just a 3D app right? So i guess you are asking how to get that sphere into a XNA game? Because XNA is a programming language it will be a bit harder to create a sphere out of triangles with it. I think you really just want to be able to import models into XNA, you can make any model with any 3D app as long as you can export it to .FBX or .X. If you just want to make planets i'd say just draw a sphere in wings3D where you can texture it properly, or might go in and add some craters. However with the world matrix you can scale models easily.

Anyway export that sphere to .FBX or.X somehow.

Then assign a model.
[color="#48d1cc"]Model MySphere;

Load model somewhere.
MySphere = content.load<[color="#48d1cc"]Model>([color="#ff0000"]"Sphere");

Then the hard part:
[color="#48d1cc"]Matrix[] transforms = [color="#0000ff"]new [color="#48d1cc"]Matrix[MySphere.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(transforms);

[color="#0000ff"] foreach ([color="#48d1cc"]ModelMesh mesh [color="#0000ff"]in MySphere.Meshes)
{
[color="#0000ff"]foreach ([color="#48d1cc"]BasicEffect effect [color="#0000ff"]in mesh.Effects)
{
effect.EnableDefaultLighting();

[color="#2e8b57"]//world matrix here you can tell where the model is located, rotated and scaled.
effect.World = transforms[mesh.ParentBone.Index] *
[color="#48d1cc"]Matrix.CreateTranslation(Vector3.Zero);

[color="#2e8b57"]//View matrix, is pretty much the camera given the camera position, it's target, and what side is up.
effect.View = [color="#48d1cc"]Matrix.CreateLookAt([color="#0000ff"]new [color="#48d1cc"]Vector3( 50, 50, 50), [color="#48d1cc"]Vector3.Zero, [color="#48d1cc"]Vector3.Up);

[color="#2e8b57"]//Projection matrix, this one is like the lens of the camera matrix, first giving the field of view then the aspect ratio and how close/far it can see objects.
effect.Projection = [color="#48d1cc"]Matrix.CreatePerspectiveFieldOfView([color="#48d1cc"]MathHelper.ToRadians(45f),
1.333f, 1, 10000);
}
[color="#2e8b57"]//All is done now draw the model.
mesh.Draw();
}
Thanks, i already have models in game, what im looking for is a way to edit them in xna. That is alter the surface to produce the same effects as in that link. How can i get access to a models vertices and muck around with em?? :)

Thanks, i already have models in game, what im looking for is a way to edit them in xna. That is alter the surface to produce the same effects as in that link. How can i get access to a models vertices and muck around with em?? :)


hmmm, not sure what exactly you want to happen. If it just is (lost the exact word) the 3D version of mipmapping 2D images (the closer you get the more detail it gets) i would load in a couple of spheres each with there own iteration/tesselation and adjust the topology with a heightmap (black 'n white image). Then just load in the correct model with the correct heightmap and texture when the model is within a certain distant range.

Sorry if this is not helpfull at all but i'm just starting XNA myself :D.
You might want to look into using vertex shaders. Basically you can apply a vertex shader to your plane sphere that moves the vertices according to that algorithm to create the continents. Not sure if it is possible to do it very easily without using shaders.

This topic is closed to new replies.

Advertisement