Righty, I am having all kinds of problems with the following Blitz3D test code, main one being I can't get the object to be in view of visable anymore, as ive pigged about with the code for ages changing allsorts. And ive also had ago and made a Center Entity routine. And I havent used Blitz for sometime now, as i've made the switch to Freebasic.
And I dont think that, the method for the sin & cos is quite right for it; especially the time replacement with blitz's milliseconds ( thats bb's time method ) I've done my best to get it as per the examples above ( which I am truely greatful for )
If anyone can shed some light onto the solution, that would be immense & awesome.
Here goes:
;
; 3D Twister V1-1
;
Const XRES=640
Const YRES=480
Graphics3D XRES,YRES,32
SetBuffer BackBuffer()
Dim vc( 512*4 )
RunTwist()
End
Function AverageX#( Entity )
Local avgx#
Surface=GetSurface( Entity, 1 )
TotalVerts=CountVertices( Surface )
For a=0 To TotalVerts-1
avgx#=avgx#+VertexX ( Surface, a )
Next
Return ( avgx# / a )
End Function
Function AverageY#( Entity )
Local avgy#
Surface=GetSurface( Entity, 1 )
TotalVerts=CountVertices( Surface )
For a=0 To TotalVerts-1
avgy#=avgy#+VertexY ( Surface, a )
Next
Return ( avgy# / a )
End Function
Function AverageZ#( Entity )
Local avgz#
surface=GetSurface( Entity, 1 )
TotalVerts=CountVertices(Surface)
For a=0 To TotalVerts-1
avgz#=avgz#+VertexZ ( Surface, a )
Next
Return ( avgz# / a )
End Function
Function RunTwist()
MainCam=CreateCamera()
PositionEntity MainCam,0,0,-5
Light=CreateLight()
While Not KeyHit(1)
Twister=CreateCuboidTwister()
PositionEntity Twister,0,0,10
EntityColor Twister,255,000,000
ScaleEntity Twister,50,50,50
CenterMesh( Twister )
RenderWorld()
FreeEntity Twister
Flip
Wend
End Function
Function CenterMesh( Entity )
Local x#=AverageX#( Entity )
Local y#=AverageY#( Entity )
Local z#=AverageZ#( Entity )
surface=GetSurface( Entity,1 )
For a=0 To CountVertices( Surface )-1
vx#=VertexX( surface, a )
vy#=VertexY( surface, a )
vz#=VertexZ( surface, a )
vx#=vx#-x#
vy#=vy#-y#
vz#=vz#-z#
VertexCoords Surface, a, vx#, vy#, vz#
Next
UpdateNormals ( Entity )
End Function
Function CreateCuboidTwister( segs=512, Parent=0 )
Entity = CreateMesh ( Parent )
surface = CreateSurface ( Entity )
For i = 0 To segs-1
v#= i / segs
y#= v*100.0
angle#= Sin(v#*12.0 - MilliSecs()*0.9)*2.5
x#= Sin(angle#)
z#= Cos(angle#)
vc(a)=AddVertex(surface, x#,y#, z#, 0.0 , v#) : a=a+1
vc(a)=AddVertex(surface, -z#,y#, x#, 0.25, v#) : a=a+1
vc(a)=AddVertex(surface, -x#,y#,-z#, 0.5 , v#) : a=a+1
vc(a)=AddVertex(surface, z#,y#,-x#, 0.75, v#) : a=a+1
Next
For i1= 0 To 3
i2= (i1+1) And 3
For j=0 To segs-2
v0=j*4+i1
v1=j*4+i2
v2=(j+1)*4+i1
v3=(j+1)*4+i2
AddTriangle( surface, vc(V0), vc(V1), vc(V2) )
AddTriangle( surface, vc(V1), vc(V3), vc(V2) )
Next
Next
UpdateNormals( Entity )
Return ( Entity )
End Function
Cheers,
Clyde.