Показать сообщение отдельно
Старый 04.10.2015, 17:40   #11
polopok
ПроЭктировщик
 
Регистрация: 17.07.2009
Сообщений: 182
Написано 51 полезных сообщений
(для 71 пользователей)
Сообщение Ответ: RagDoll physic. Физика взаимодействия

Пример Инверсной кинематики ( система костей ) на основе ragdoll
inverseKinematic.exe

параметр lenght лучше объявить в Типе
Код под спойлером :
;


Const lenght  = 100
Global NumberOfPoints 

.points
Type Point 
Field  id% ,x# , y# , z# , w# , lock ; lenght  
Field AP.Point , BP.Point ; After point = AP ,Before point = BP
End Type 

Global CP.Point ; Curet point = CP

Function NewPoint.Point ()
    this.Point = New Point 
    this\bp= Null 
    this\ap= Null
    this\x = 0.0
    this\y = 0.0
    this\z = 0.0
    this\w = 1.0
    this\lock = False
    NumberOfPoints= NumberOfPoints+1
    this\id = NumberOfPoints
    Return this
End Function 

Function SetLockPoint(this.Point , lock)
    this\lock = lock
End Function

Function SetPositionPoint(this.Point ,Point_X# ,Point_Y#   ); object ,radius  
     this\x = Point_X : this\y = Point_Y 
End Function

Function DeletePoint(this.Point )
    If this <> Null Delete this 
    NumberOfPoints = NumberOfPoints -1
End Function

Function ClearPoints( )
    Delete Each point 
    NumberOfPoints = 0
End Function

Global grx,gry
Global mx#,my#,mz%  , offsetX# ,offsetY#

Graphics 800,600,32,2
SetBuffer BackBuffer()
grx = GraphicsWidth()/2 : gry = GraphicsHeight()/2

cp = newpoint()
setpositionpoint (cp,200,200)
setlockpoint(cp,true)
cp\ap = After cp : cp\bp = Before cp
cp = newpoint()
setpositionpoint (cp,200+lenght  ,200)
cp\ap = After cp : cp\bp = Before cp
cp = newpoint()
setpositionpoint (cp,200+lenght  *2,200)
cp\ap = After cp : cp\bp = Before cp
cp = newpoint()
setpositionpoint (cp,200+lenght  *3,200)
cp\ap = After cp : cp\bp = Before cp

For p.point = Each point
    If p <> Null
        DebugLog " Point : " + p\id
        DebugLog "        L___ Position : X =  "+p\x+"  , Y =  "+p\y+"  , Z =  "+p\z+"  , W =  "+p\w
        DebugLog "        L___ Lock =  "+ p\lock
        DebugLog ""
    EndIf
Next

While Not KeyHit(1)
Cls 
mx = MouseX() : my = MouseY() : mz = MouseZ()

If MouseDown(1) mouseClick = True Else mouseClick = False

For p.point = Each point
    If p <> Null
        If mouseClick = True
            cp = Last point
            cp\x = mx : cp\y = my
        EndIf 
        
        cp = p\bp
        If cp <> Null        
            dx# = p\x - cp\x
            dy# = p\y - cp\y
            MathPoint(dx#,dy#,lenght ) ; p\lenght  !!!
            If p\lock = False    
                p\x = p\x + offsetX 
                p\y = p\y + offsetY
            EndIf    
            If cp\lock = False    
                cp\x = cp\x - offsetX
                cp\y = cp\y - offsetY
            EndIf        
        

            
        EndIf
    EndIf
Next

For pp.point = Each point
    If pp <> Null
        cp = pp\bp
        If cp <> Null    
            Line pp\x,pp\y,cp\x,cp\y
        EndIf

        if pp\lock 
color 255,0,0
Oval pp\x -2 , pp\y - 2 ,4 ,4 ,1
else
color 255,255,255
Oval pp\x -2 , pp\y - 2 ,4 ,4 ,1
endif

    EndIf
Next    
Flip 
Wend
ClearPoints()
End 

Function Distance2#(dx#, dy#)
    Return  (dx * dx + dy * dy)^0.5
End Function

Function MathPoint#(dx#,dy#,length# )
    dis# =Distance2(dx#, dy#)
    diff# =Different( length#, dis )
    offsetX# = Offset(diff , dx, dis) 
    offsetY# = Offset(diff , dy, dis) 
End Function

Function Different#( length#, distance# )
    Return  length - distance
End Function

Function Offset#(differente#,diffs # ,distance# )
    Return   (differente* diffs / distance) ;
End Function
__________________
Мой проект здесь
(Offline)
 
Ответить с цитированием
Эти 2 пользователя(ей) сказали Спасибо polopok за это полезное сообщение:
Arton (04.10.2015), St_AnGer (05.10.2015)