Code archives/3D Graphics - Mesh/Asteroids
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
Basically this creates a blitz sphere and munches the verts around a bit to make it more random. The 'clever' bit is it checks all the verts that are joined together first so you don't get cracks and stuff. But it's nice as a no-media solution. You can infact throw any mesh at this and it will randomise it... | |||||
; Rob Farley 2004 ; rob@mentalillusion.co.uk Graphics3D 640,480 ; create asteroid sphere asteroid=CreateSphere(8) ;EntityTexture asteroid(ast),astex ; monkey with the verts as1=GetSurface(asteroid,1) ; record the locations of the verts Dim vpos#(CountVertices(as1)-1,3) For n=0 To CountVertices(as1)-1 vpos(n,0)=VertexX(as1,n) vpos(n,1)=VertexY(as1,n) vpos(n,2)=VertexZ(as1,n) vpos(n,3)=0 Next For n=0 To CountVertices(as1)-1 ; change these to make it more or less messy xm#=Rnd(-.1,.1) ym#=Rnd(-.1,.1) zm#=Rnd(-.1,.1) For nn=0 To CountVertices(as1)-1 ; if the vert has not been monkeyed with monkey away If vpos(nn,3)=0 If vpos(n,0)=vpos(nn,0) And vpos(n,1)=vpos(nn,1) And vpos(n,2)=vpos(nn,2) VertexCoords as1,nn,vpos(nn,0)+xm,vpos(nn,1)+ym,vpos(nn,2)+zm vpos(nn,3)=1 EndIf EndIf Next Next ; draw it camera = CreateCamera():PositionEntity camera,0,0,-5 light = CreateLight(2):PositionEntity light,1000,1000,-500 Repeat TurnEntity asteroid,0,1,2 RenderWorld Flip Until KeyHit(1) |
Comments
| ||
nice one. space odyssee from a hand full of code. |
| ||
Hey, this could be used to create popcorn - lots of popcorn. |
| ||
Welldone Dude :) |
| ||
Nice. :) I messed with it and found that if you set the vales to (-.5,.5), you get a perfect, and I mean PERFECT model of a piece of paper that's been crumpled up into a ball! Ideal for YOUR garbage-collection game! :D Okay, maybe not, but these "trash" models always look fake in games like Half-Life, and now I find out that this code can churn out an unlimited variety of unique, interesting trash. |
| ||
The actual deformation function Morph(Mesh) is perfect for making randomised cliff faces from flat meshes very quickly and without too much clipping. Rerally useful, thanks :D |
| ||
Nice. Tested with this texture ;) http://www.filterforge.com/filters/6296.html JP |
Code Archives Forum