About omega and torque i must say it is useful to me.
I did this somedays ago to implement some other stuff to it to explain via video some behaviour about inertial fields....
Code: Select all
;Peonza Conica (21 Agosto 2015)
;/ inits
Define .f
ExamineDesktops()
Global bitplanes.a=DesktopDepth(0),RX.u=DesktopWidth(0)*2/3,RY.u=DesktopHeight(0)*0.6:MP_Graphics3DWindow(0,0,RX,RY,"Peonza conica",#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SystemMenu):MP_VSync(1):MP_SetAntialiasing(4)
; Global bitplanes.a=DesktopDepth(0),RX.u=DesktopWidth(0),RY.u=DesktopHeight(0):MP_Graphics3D(RX,RY,bitplanes,0):MP_VSync(1):MP_SetAntialiasing(4):SetWindowTitle(0,"Peonza conica")
Global ShowCursor.b=0,CursorX=RX/2,CursorY=RY/2,showgui.b=1,mdx,mdy
Global font.i=MP_LoadFont("Tahoma",20,1,0)
Structure D3DMATRIX
_11.f : _12.f : _13.f : _14.f
_21.f : _22.f : _23.f : _24.f
_31.f : _32.f : _33.f : _34.f
_41.f : _42.f : _43.f : _44.f
EndStructure
Structure D3DXVECTOR3
x.f
y.f
z.f
EndStructure
Structure Vector3D Extends D3DXVECTOR3
m.f;<-length(modulo)
EndStructure
MP_PhysicInit()
;\
Global.i camara,pivotcam,light,chapa,piv,stone,stone2,fondo,fondotexture,bola,disco,mastileje,pivot
;/ Luz
light.i=MP_CreateLight(1)
MP_LightSetColor(light,$FFFFFF)
MP_PositionEntity(light,4,4,0)
MP_CreateSkyBox("..\media\skyboxsun5deg","jpg",100)
;\
Procedure.i Matriz4x4xMatriz4x4(*a.D3DMATRIX,*b.D3DMATRIX,*prod.D3DMATRIX); producto
*prod\_11=*a\_11**b\_11+*a\_12**b\_21+*a\_13**b\_31+*a\_14**b\_41:*prod\_12=*a\_11**b\_12+*a\_12**b\_22+*a\_13**b\_32+*a\_14**b\_42:*prod\_13=*a\_11**b\_13+*a\_12**b\_23+*a\_13**b\_33+*a\_14**b\_43:*prod\_14=*a\_11**b\_14+*a\_12**b\_24+*a\_13**b\_34+*a\_14**b\_44
*prod\_21=*a\_21**b\_11+*a\_22**b\_21+*a\_23**b\_31+*a\_24**b\_41:*prod\_22=*a\_21**b\_12+*a\_22**b\_22+*a\_23**b\_32+*a\_24**b\_42:*prod\_23=*a\_21**b\_13+*a\_22**b\_23+*a\_23**b\_33+*a\_24**b\_43:*prod\_24=*a\_21**b\_14+*a\_22**b\_24+*a\_23**b\_34+*a\_24**b\_44
*prod\_31=*a\_31**b\_11+*a\_32**b\_21+*a\_33**b\_31+*a\_34**b\_41:*prod\_32=*a\_31**b\_12+*a\_32**b\_22+*a\_33**b\_32+*a\_34**b\_42:*prod\_33=*a\_31**b\_13+*a\_32**b\_23+*a\_33**b\_33+*a\_34**b\_43:*prod\_34=*a\_31**b\_14+*a\_32**b\_24+*a\_33**b\_34+*a\_34**b\_44
*prod\_41=*a\_41**b\_11+*a\_42**b\_21+*a\_43**b\_31+*a\_44**b\_41:*prod\_42=*a\_41**b\_12+*a\_42**b\_22+*a\_43**b\_32+*a\_44**b\_42:*prod\_43=*a\_41**b\_13+*a\_42**b\_23+*a\_43**b\_33+*a\_44**b\_43:*prod\_44=*a\_41**b\_14+*a\_42**b\_24+*a\_43**b\_34+*a\_44**b\_44
ProcedureReturn *prod
EndProcedure
Procedure.i flecha(px.f=0,py.f=0,pz.f=0,x.f=1,y.f=0,z.f=0,color.l=$EE3333,lados.a=8)
Protected mod.f=Sqr(x*x+y*y+z*z),cil.i=MP_CreateCylinder(lados,mod),cono.i=MP_CreateCone(lados,mod/8):ciltexture=MP_CreateTextureColor(8,8,color)
MP_ResizeMesh(cil,mod/80,mod/80,mod)
MP_TranslateMesh(cil,0,0,mod/2)
MP_RotateMesh(cono,180,0,180)
MP_ResizeMesh(cono,mod/20,mod/20,mod/10)
MP_TranslateMesh(cono,0,0,mod)
MP_AddMesh(cono,cil):MP_FreeEntity(cono)
; MP_EntityLookAt(cil,x+0.000001,y,z,0,0)
MP_PositionEntity(cil,px,py,pz)
MP_EntitySetTexture(cil,ciltexture,0,0)
ProcedureReturn cil
EndProcedure
Procedure.i BaseSistemaCoordenadas(px.f=0,py.f=0,pz.f=0,colorx.l=$EEAA88,colory.l=$22AADD,colorz.l=$AADDAA,lados.a=8)
Protected vx.i=flecha(px,py,pz,1,0,0,colorx,lados)
Protected vy.i=flecha(px,py,pz,0,1,0,colory,lados)
Protected vz.i=flecha(px,py,pz,0,0,1,colorz,lados)
MP_AddMesh(vx.i,vy.i);:MP_FreeEntity(vx.i)
MP_AddMesh(vz.i,vy.i);:MP_FreeEntity(vz.i)
ProcedureReturn vy.i
EndProcedure
; baseglobal.i=BaseSistemaCoordenadas(-1.5,1,0)
flecha.i=flecha()
MP_ScaleMesh(flecha,4,4,1)
MP_HideEntity(flecha,1)
;
camara=MP_CreateCamera():pivotcam.i=MP_CreateMesh():MP_EntitySetParent(camara,pivotcam,0):MP_PositionEntity(camara,0,0,-3):MP_TurnEntity(pivotcam,18,0,0,0)
;
fondo=MP_CreateRectangle(20,0,20)
MP_PositionEntity(fondo,0,-1,0)
fondotexture=MP_LoadTexture("..\media\wood-floor2.jpg",0,0)
MP_EntitySetTexture(fondo,fondotexture,0,0)
MP_EntityPhysicBody(fondo,1,0)
;
mastileje=MP_CreateCylinder(8,2)
MP_RotateMesh(mastileje,90,0,0)
MP_ScaleMesh(mastileje,0.05,0.5,0.05)
MP_PositionEntity(mastileje,0,-0.5,0)
MP_EntityPhysicBody(mastileje,1,0)
bola=MP_CreateSphere(4):MP_MaterialEmissiveColor(bola,$bb,$8E,$AA,$FB):MP_ResizeMesh(bola,0.1,0.1,0.1)
#verticesdisco=6
disco=MP_CreateCylinder(#verticesdisco,0.01)
MP_RotateMesh(disco,90,-90,0)
MP_MeshSetAlpha(disco,2)
; discocolor.l=$99AAAABB:discoTexture.i=MP_CreateTextureColor(8,8,discocolor):MP_EntitySetTexture(disco,discoTexture,0,0)
MP_MaterialDiffuseColor(disco,$55,$1E,$FA,$EB):MP_MaterialEmissiveColor(disco,$99,$AE,$BA,$6B)
MP_EntityPhysicBody(disco,3,1)
;
MP_ConstraintCreateBall(disco,0,1,0,1,0,0,0,0,mastileje)
;Bisagras:
Dim bisagra.i(#verticesdisco-1):Dim pesa.i(#verticesdisco-1):Dim hilo.i(#verticesdisco-1):rad=1
For t.a=0 To #verticesdisco-1
posx=rad*Cos(#PI*(t/#verticesdisco*2-1))
posz=rad*Sin(#PI*(t/#verticesdisco*2-1))
bisagra(t)=MP_CreateSphere(4):MP_ResizeMesh(bisagra(t),0.02,0.02,0.02)
pesa(t)=MP_CreateSphere(12):MP_ResizeMesh(pesa(t),0.08,0.08,0.08)
hilo(t)=MP_CreateCylinder(6,1):MP_RotateMesh(hilo(t),-90,0,0):MP_ResizeMesh(hilo(t),0.005,0.3,0.005):MP_TranslateMesh(hilo(t),0,0.15,0):MP_MaterialEmissiveColor(hilo(t),$99,$BB,$56,$89)
MP_TranslateMesh(bisagra(t),posx,0,posz)
MP_PositionEntity(pesa(t),posx,-0.3,posz)
MP_EntitySetParent(hilo(t),pesa(t),0)
MP_AddMesh(bisagra(t),disco):MP_FreeEntity(bisagra(t))
Next
For t.a=0 To #verticesdisco-1
MP_EntityPhysicBody(pesa(t),3,0.1)
MP_ConstraintCreateBall(pesa(t),0,0,1,0,0,0,0.3,0,disco)
Next
MP_MouseInWindow()
MP_UseCursor(0)
pesa.a=0
While MP_KeyDown(#PB_Key_Escape)=0 And WindowEvent()<>#PB_Event_CloseWindow
mdx=MP_MouseDeltaX()/200:mdy=MP_MouseDeltaY()/200:mdw=MP_MouseDeltaWheel()/400
If MP_KeyHit(#PB_Key_Space)
ElseIf MP_KeyHit(#PB_Key_W)
wf.b!1
MP_Wireframe(wf.b)
ElseIf MP_KeyDown(#PB_Key_Left)
; MP_EntitySetOmega(disco,0,1,0)
MP_EntityAddImpulse(disco,0,0,1,-10,0,0)
MP_EntityAddImpulse(disco,0,0,-1,10,0,0)
ElseIf MP_KeyDown(#PB_Key_Right)
; MP_EntitySetOmega(disco,0,-1,0)
MP_EntityAddImpulse(disco,0,0,-1,-10,0,0)
MP_EntityAddImpulse(disco,0,0,1,10,0,0)
ElseIf MP_KeyHit(#PB_Key_Up)
ElseIf MP_KeyHit(#PB_Key_Down)
ElseIf MP_KeyHit(#PB_Key_End)
MP_HideEntity(flecha,1)
ElseIf MP_KeyHit(#PB_Key_F5)
ElseIf MP_MouseButtonDown(1)
; picked.i=MP_PickCamera(camara,WindowMouseX(0),WindowMouseY(0))
; If picked
; MP_PositionEntity(pivotcam,MP_EntityGetX(picked,0),MP_EntityGetY(picked,0),MP_EntityGetZ(picked,0))
; EndIf
MP_MoveEntity(pivotcam,mdx,-mdy,0)
Else
MP_TurnEntity(pivotcam,mdy*60,mdx*60,0,0)
If mdw
MP_EntitySetZ(camara,MP_EntityGetZ(camara)+mdw); <- MP_MoveEntity(cam,0,0,mdw)
EndIf
If MP_KeyDown(#PB_Key_Left)
MP_MoveEntity(pivotcam,-0.1,0,0)
ElseIf MP_KeyDown(#PB_Key_Right)
MP_MoveEntity(pivotcam,0.1,0,0)
ElseIf MP_KeyDown(#PB_Key_Up)
MP_MoveEntity(pivotcam,0,0.1,0)
ElseIf MP_KeyDown(#PB_Key_Down)
MP_MoveEntity(pivotcam,0,-0.1,0)
EndIf
EndIf
MP_PhysicUpdate()
MP_RenderWorld()
MP_Flip():Delay(8)
Wend
MP_PhysicEnd()