Гигант индустрии
Регистрация: 14.12.2005
Сообщений: 2,785
Написано 1,183 полезных сообщений (для 4,437 пользователей)
|
Re: модель из Желе
;********************DEMO 2****************
Graphics3D 640,480,32
HidePointer
;gravitation
Global grav_x#= 0
Global grav_y#=-0.08
Global grav_z#= 0
;hohe des bodens
Global ground%=-5
Global camera=CreateCamera()
PositionEntity camera,0,1,-24
Global light=CreateLight()
LightColor light,200,200,200
;spiegelnder untergrund
plane=CreatePlane()
PositionEntity plane,0,ground,0
EntityColor plane,20,20,100
EntityAlpha plane,0.85
mirror=CreateMirror(plane)
MoveEntity mirror,0,0.01,0
Type mass
Field x#,y#,z#
Field xs#,ys#,zs#
Field xo#,yo#,zo#
Field fix%
End Type
Type spring
Field m1%,m2%
Field l#
End Type
Type face
Field surf%
Field m1%,m2%,m3%,m4%
Field v1%,v2%,v3%,v4%
End Type
Dim cube(6)
Dim texture(6)
Function add_mass(x#,y#,z#,f%)
m.mass=New mass
m\x=x
m\y=y
m\z=z
m\fix=f
Return Handle(m)
End Function
Function add_spring(m1%,m2%)
ma1.mass = Object.mass(m1)
ma2.mass = Object.mass(m2)
s.spring = New spring
s\m1 = m1
s\m2 = m2
s\l = ( ( ma1\x - ma2\x )^2 + ( ma1\y - ma2\y )^2 + ( ma1\z - ma2\z )^2 )
Return Handle(s)
End Function
Function add_face(mesh%, m1%,m2%,m3%,m4%)
ma1.mass = Object.mass(m1)
ma2.mass = Object.mass(m2)
ma3.mass = Object.mass(m3)
ma4.mass = Object.mass(m4)
f.face=New face
f\surf=CreateSurface(mesh)
f\m1=m1
f\m2=m2
f\m3=m3
f\m4=m4
f\v1=AddVertex (f\surf,ma1\x,ma1\y,ma1\z, 0,0)
f\v2=AddVertex (f\surf,ma2\x,ma2\y,ma2\z, 1,0)
f\v3=AddVertex (f\surf,ma3\x,ma3\y,ma3\z, 1,1)
f\v4=AddVertex (f\surf,ma4\x,ma4\y,ma4\z, 0,1)
AddTriangle f\surf,f\v1,f\v2,f\v3
AddTriangle f\surf,f\v1,f\v3,f\v4
End Function
Function update_object()
;update federn
For t=1 To 3
For s.spring = Each spring
m1.mass = Object.mass(s\m1)
m2.mass = Object.mass(s\m2)
lx# = ( m1\x + m1\xs ) - ( m2\x + m2\xs )
ly# = ( m1\y + m1\ys ) - ( m2\y + m2\ys )
lz# = ( m1\z + m1\zs ) - ( m2\z + m2\zs )
lg# = ( lx * lx + ly * ly + lz * lz )
ld# = 0.2 * ( s\l - lg ) / lg
lx = ( lx * ld )
ly = ( ly * ld )
lz = ( lz * ld )
m1\xs = m1\xs + lx
m1\ys = m1\ys + ly
m1\zs = m1\zs + lz
m2\xs = m2\xs - lx
m2\ys = m2\ys - ly
m2\zs = m2\zs - lz
Next
Next
;update massen
For m.mass = Each mass
m\xo = m\x
m\yo = m\y
m\zo = m\z
If ( m\y + m\ys ) > ground Then
m\xs = m\xs + grav_x
m\ys = m\ys + grav_y
m\zs = m\zs + grav_z
If m\fix = False Then
m\x = m\x + m\xs
m\y = m\y + m\ys
m\z = m\z + m\zs
Else
m\xs = 0
m\ys = 0
m\zs = 0
EndIf
Else
m\y = ground
m\xs = 0
m\ys = 0
m\zs = 0
EndIf
Next
;update faces
For f.face = Each face
ma1.mass = Object.mass(f\m1)
ma2.mass = Object.mass(f\m2)
ma3.mass = Object.mass(f\m3)
ma4.mass = Object.mass(f\m4)
VertexCoords f\surf,f\v1,ma1\x,ma1\y,ma1\z
VertexCoords f\surf,f\v2,ma2\x,ma2\y,ma2\z
VertexCoords f\surf,f\v3,ma3\x,ma3\y,ma3\z
VertexCoords f\surf,f\v4,ma4\x,ma4\y,ma4\z
Next
For t=0 To 5
;UpdateNormals cube(t)
Next
End Function
Function check_mouse()
For m.mass=Each mass
If m\y<=ground Then floor_hit=True:Exit
Next
If floor_hit Then
mx# = MouseXSpeed() * 0.02
my# = MouseYSpeed() * 0.02
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
If MouseHit(1) Then mz#=15
m.mass = Last mass
m\xs = m\xs + mx
m\zs = m\zs - my
m\ys = m\ys + mz
EndIf
End Function
Function Create_Cube()
;massenpunkte festlegen
m0 = add_mass (-5, 5,-5, False)
m1 = add_mass ( 5, 5,-5, False)
m2 = add_mass ( 5,-5,-5, False)
m3 = add_mass (-5,-5,-5, False)
m4 = add_mass (-5, 5, 5, False)
m5 = add_mass ( 5, 5, 5, False)
m6 = add_mass ( 5,-5, 5, False)
m7 = add_mass (-5,-5, 5, False)
mm = add_mass ( 0, 0, 0, False)
;massen mit federn verbinden
add_spring (mm,m0)
add_spring (mm,m1)
add_spring (mm,m2)
add_spring (mm,m3)
add_spring (mm,m4)
add_spring (mm,m5)
add_spring (mm,m6)
add_spring (mm,m7)
add_spring (m0,m1)
add_spring (m1,m2)
add_spring (m2,m3)
add_spring (m3,m0)
add_spring (m4,m5)
add_spring (m5,m6)
add_spring (m6,m7)
add_spring (m7,m4)
add_spring (m0,m4)
add_spring (m1,m5)
add_spring (m2,m6)
add_spring (m3,m7)
add_spring (m0,m6)
add_spring (m1,m7)
add_spring (m5,m3)
add_spring (m4,m2)
add_spring (m0,m2)
add_spring (m1,m3)
add_spring (m4,m6)
add_spring (m5,m7)
add_spring (m0,m7)
add_spring (m3,m4)
add_spring (m1,m6)
add_spring (m5,m2)
add_spring (m0,m5)
add_spring (m1,m4)
add_spring (m2,m7)
add_spring (m3,m6)
;wurfelmesh + texturen erstellen
SetFont LoadFont("arial",300)
For t=0 To 5
cube(t)=CreateMesh()
EntityFX cube(t),4
EntityShininess cube(t),0.5
texture(t)=CreateTexture(256,256)
SetBuffer TextureBuffer(texture(t))
Color Rnd(0,255),Rnd(0,255),Rnd(0,255)
ClsColor ColorRed(),ColorGreen(),ColorBlue():Cls
Color 255-ColorRed(),255-ColorGreen(),255-ColorBlue()
Text 128,128,t+1,1,1
Next
add_face (cube(0),m0,m1,m2,m3)
add_face (cube(1),m6,m5,m4,m7)
add_face (cube(2),m5,m6,m2,m1)
add_face (cube(3),m0,m3,m7,m4)
add_face (cube(4),m4,m5,m1,m0)
add_face (cube(5),m3,m2,m6,m7)
For t=0 To 5
EntityTexture cube(t),texture(t)
Next
End Function
create_cube()
SetBuffer BackBuffer()
Color 255,255,255
SetFont LoadFont("arial",20)
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
While Not KeyHit(1)
update_object()
check_mouse()
Delay(15)
RenderWorld()
Text 0,0,"Maus bewegen, Mausknopf drucken"
Flip
Wend
End
__________________
|