Hemisphere
Blitz3D Forums/Blitz3D Programming/Hemisphere
| ||
In making a hemisphere mesh, I made use of Beaker's copypartmesh function to basically copy half of a sphere primitive. The result is here, and it works: Function CreateHemisphere(Segments=8,Parent=False) If (Segments<2) Then Segments=2 Local Mesh=CreateSphere(Segments) Local SourceSurface = GetSurface(Mesh,1) Local Hemisphere = CreateMesh(Parent) Local DestinationSurface = CreateSurface(Hemisphere) Local HalfwayVert=(((CountVertices(SourceSurface)) Shr 1)+segments+1) Local IterVerts Local AddVert Local InitialVertex Local v0,v1,v2 For IterVerts= 0 To HalfwayVert-1 AddVert = AddVertex(DestinationSurface,VertexX(SourceSurface,IterVerts),VertexY(SourceSurface,IterVerts),VertexZ(SourceSurface,IterVerts), VertexU(SourceSurface,IterVerts),VertexV(SourceSurface,IterVerts)) VertexNormal DestinationSurface,AddVert,VertexNX(SourceSurface,IterVerts),VertexNY(SourceSurface,IterVerts),VertexNZ(SourceSurface,IterVerts) If (Not(IterVerts)) InitialVertex = AddVert EndIf Next Local IterTris For IterTris = 0 To CountTriangles(SourceSurface)-1 v0 = TriangleVertex(SourceSurface ,IterTris,0) v1 = TriangleVertex(SourceSurface ,IterTris,1) v2 = TriangleVertex(SourceSurface ,IterTris,2) If ((v0 => 0) + (v0 <= HalfwayVert)) + ((v2 => 0) + (v2 <= HalfwayVert)) + ((v1 => 0) + (v1 <= HalfwayVert)) v0 = InitialVertex+v0 v1 = InitialVertex+v1 v2 = InitialVertex+v2 AddTriangle(DestinationSurface,v0,v1,v2) EndIf Next FreeEntity Mesh Mesh=False Return Hemisphere End Function However, there's two things that I am unssure of: 1) The interior of the hemisphere seems to be an inverted cone, and whilst it's not a problem for MY usage, it seems a bit weird that it's there and like this, rather than those triangles forming a flat base. 2) Being poor at trig, I failed miserably when I tried to make th e hemisphere from scratch by writing to a file all the vertex and normal data, and then triangle data, in the loops. The problem here, was that there's no means to affect the "Segments" parameter when building the mesh from the raw data collected this way. |
| ||
Knocked up this, any good?Graphics3D 640,480,32,1 Global LIGHT = CreateLight() Global CAMERA = CreateCamera() : PositionEntity CAMERA, 0,0,-5 Global TEST = MESHhemisphere() : EntityFX TEST, 4 : EntityColor TEST, 50,50,200 While Not KeyHit(1) TurnEntity TEST, .5,0,.5 RenderWorld() Flip Wend Function MESHhemisphere( Segs = 8 ) Local tmp, mesh, s, v, t, ns, v0, v1, v2, nv0, nv1, nv2 tmp = CreateSphere( Segs ) s = GetSurface( tmp, 1 ) For v = 0 To CountVertices(s)-1 If VertexY( s, v ) < 0 VertexCoords s, v, VertexX(s,v), 0 , VertexZ(s,v) VertexNormal s, v, 0, 0, 0 EndIf Next mesh = CreateMesh() ns = CreateSurface( mesh ) For t = 0 To CountTriangles( s )-1 v0 = TriangleVertex( s, t, 0 ) v1 = TriangleVertex( s, t, 1 ) v2 = TriangleVertex( s, t, 2 ) If VertexNY( s,v0 ) <> 0 Or VertexNY( s, v1 ) <> 0 Or VertexNY( s, v2) <> 0 nv0 = AddVertex( ns, VertexX( s, v0 ), VertexY( s, v0 ) , VertexZ( s, v0 ) ) nv1 = AddVertex( ns, VertexX( s, v1 ), VertexY( s, v1 ) , VertexZ( s, v1 ) ) nv2 = AddVertex( ns, VertexX( s, v2 ), VertexY( s, v2 ) , VertexZ( s, v2 ) ) VertexNormal ns, nv0, VertexNX( s, v0 ) , VertexNY( s, v0 ) , VertexNZ( s, v0 ) VertexNormal ns, nv1, VertexNX( s, v1 ) , VertexNY( s, v1 ) , VertexNZ( s, v1 ) VertexNormal ns, nv2, VertexNX( s, v2 ) , VertexNY( s, v2 ) , VertexNZ( s, v2 ) AddTriangle ns, nv0, nv1, nv2 EndIf Next FreeEntity tmp Return mesh End Function |
| ||
Perfect! You've gotten rid of the 'base' altogoether, which is ideal for me! Thanks, Stevie. |