Hi all :) Now can someone help me fix this code so it works on ANY mesh, whether its animated or not?
here's the code:
AppTitle "Sample #21 of Newton Wrapper. Water."
Global body
Global mesh
Graphics3D 600,600,32,2
Include "newton.bb"
cam = CreateCamera()
CameraClsColor cam,25,30,70
PositionEntity cam,0,10,-30
light= CreateLight()
RotateEntity light,20,50,0
plane = CreatePlane()
celltex = LoadTexture("Cell.bmp")
EntityColor plane,50,200,255
EntityAlpha plane,.5
EntityTexture plane,celltex
ScaleTexture celltex,30,30
; -- create physic world
phWorldCreate(0,"your license key") ;no rigit plane
;play it!
While Not(KeyHit(1))
;create new primitive
primit = Rand(1,50)
If primit <5
dx# = Rnd(.5,3):dy# = Rnd(.5,3):dz# = Rnd(.5,3);size
dx = 1:dy=1:dz=1
mass# = 10;Rnd(.1,.2)
;Create corresponded primitive
Select primit
Case 1;cube
body = phBodyCreateBox(dx,dy,dz,mass)
mesh = CreateCube()
ScaleEntity mesh,dx*.5,dy*.5,dz*.5
Case 2;ellipsoid
body = phBodyCreateSphere(dx,dy,dz,mass)
mesh = CreateSphere()
ScaleEntity mesh,dx,dy,dz
Case 3;cylinder
body = phBodyCreateCyl(dx,dy,mass)
mesh = CreateCylinder()
ScaleEntity mesh,dx,dy*.5,dx
Case 4;cone
body = phBodyCreateCone(dx,dy*2,mass)
mesh = CreateCone(20)
ScaleEntity mesh,dx,dy,dx
End Select
NewObj.phx = New phx
NewObj\mesh = mesh
NewObj\body = body
UpdatePhysics(body)
EntityColor mesh,Rnd(0,255),Rnd(0,255),Rnd(0,255)
EndIf
WorldStep(0.05)
RenderWorld
Flip
Wend
Function UpdatePhysics(body)
;set random position, velocity and rotation
phBodySetPos(body,Rnd(-10,10),Rnd(3,7),Rnd(1,1))
phBodySetVel(body,Rnd(-2,2),Rnd(-12,2),Rnd(-2,2))
phBodySetRot(body,Rnd(-180,180),Rnd(-180,180),Rnd(-180,180))
; !!!!!!!!!!! Set Water plane for each body
phBodySetWater(body, 0,0,0, 0,1,0, 15, 0.3,0.4)
End Function
;~IDEal Editor Parameters:
;~C#Blitz3D194
Thanks!
~SI~
|