Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - .NET

Страница: 1 | 2 |

 

  Вопрос: Гравицапа Добавлено: 21.07.09 18:19  

Автор вопроса:  ☺♣FIO♣☺
Кто имел опыт с гравицапой? Как это сделать в vb?

Ответить

  Ответы Всего ответов: 17  

Номер ответа: 1
Автор ответа:
 ☺♣FIO♣☺



Вопросов: 35
Ответов: 160
 Профиль | | #1 Добавлено: 21.07.09 18:49
гравитация...

Ответить

Номер ответа: 2
Автор ответа:
 VβÐUηìt



Вопросов: 246
Ответов: 3333
 Web-сайт: смекаешь.рф
 Профиль | | #2
Добавлено: 21.07.09 19:02
Ты о чем?

Ответить

Номер ответа: 3
Автор ответа:
 ☺♣FIO♣☺



Вопросов: 35
Ответов: 160
 Профиль | | #3 Добавлено: 21.07.09 19:09
о гравитации. Допустим, есть шарик и пол. Шарик должен упасть напол с реальной скоростью и отскочить по законам физики. Короче нужна физика в вбнет.

Ответить

Номер ответа: 4
Автор ответа:
 User Unknown



Вечный Юзер!

ICQ: uu@jabber.cz 

Вопросов: 120
Ответов: 3302
 Профиль | | #4 Добавлено: 21.07.09 20:56
А хрен его знает что это такое. Компилировать и запускать на свой страх и риск. Я просто оставлю это здесь (Form1.frm):

  1.  
  2. VERSION 5.00
  3. Begin VB.Form Form1
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   3195
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   4680
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   3195
  11.    ScaleWidth      =   4680
  12.    StartUpPosition =   3  'Windows Default
  13. End
  14. Attribute VB_Name = "Form1"
  15. Attribute VB_GlobalNameSpace = False
  16. Attribute VB_Creatable = False
  17. Attribute VB_PredeclaredId = True
  18. Attribute VB_Exposed = False
  19. Option Explicit
  20.  
  21. Private Enum CONST_INTEGRATOR
  22.  
  23.     FORWARD_EULER = 0
  24.     SECOND_ORDER_EULER = 1
  25.     VERLET = 2
  26.     VELOCITY_VERLET = 3
  27.     SECOND_ORDER_RUNGE_KUTTA = 4
  28.     THIRD_ORDER_RUNGE_KUTTA = 5
  29.     FORTH_ORDER_RUNGE_KUTTA = 6
  30.     
  31. End Enum
  32.  
  33. Private Type POINT2D
  34.  
  35.     X As Double
  36.     Y As Double
  37.  
  38. End Type
  39.  
  40. Private Type VECTOR2D
  41.  
  42.     X As Double
  43.     Y As Double
  44.  
  45. End Type
  46.  
  47. Private Type FORCE2D
  48.  
  49.     Net As VECTOR2D
  50.  
  51. End Type
  52.  
  53.  
  54. Private Type TORQUE2D
  55.  
  56.     Net As Double
  57.  
  58. End Type
  59.  
  60. Private Type PHYSICS2D
  61.     
  62.     Position As POINT2D
  63.     Velocity As VECTOR2D
  64.     Acceleration As VECTOR2D
  65.     Angle As Double
  66.     Angular_Velocity As Double
  67.     Angular_Acceleration As Double
  68.     Force As FORCE2D
  69.     Torque As TORQUE2D
  70.     Mass As Double
  71.     One_Over_Mass As Double
  72.     Inertia As Double
  73.     One_Over_Inertia As Double
  74.     Elasticity As Double
  75.     Momentum As VECTOR2D
  76.     Impulse As VECTOR2D
  77.     Angular_Momentum As VECTOR2D
  78.     Angular_Impulse As VECTOR2D
  79.     Scalar As Double
  80.     Friction_Coefficient As Double
  81.     Drag_Coefficient As Double
  82.     Area As Double
  83.     
  84. End Type
  85.  
  86. Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
  87. Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
  88.  
  89. Private Const EARTH_GRAVITY As Double = 9.80665
  90. Private Const AIR_DENSITY As Double = 1.125
  91.  
  92. Private Const POUNDS_TO_KG As Double = 0.45359237
  93.  
  94. Private Const ONE_KGF_CM_TO_NEWTONS_CM As Double = 9.80665
  95. Private Const TWO_KGF_CM_TO_NEWTONS_CM As Double = 9.80665 * 2
  96. Private Const THREE_KGF_CM_TO_NEWTONS_CM As Double = 9.80665 * 3
  97. Private Const FOUR_KGF_CM_TO_NEWTONS_CM As Double = 9.80665 * 4
  98.  
  99. Private Ticks_Per_Second As Currency
  100. Private Start_Time As Currency
  101. Private Milliseconds As Currency
  102.  
  103. Private Get_Frames_Per_Second As Long
  104. Private Frame_Count As Long
  105.  
  106. Private Running As Boolean
  107.  
  108. Private Time As Double
  109. Private Delta_Time As Currency
  110. Private Accumulator As Double
  111. Private Obj As PHYSICS2D
  112. Private Time_Step As Double
  113.  
  114. Private Neutral_Flag As Boolean
  115. Private Key_State As Long, Key_Flag As Long
  116.  
  117. Private Flag As Boolean
  118.  
  119. Private Old_Position As POINT2D
  120.  
  121. Private Sub Main()
  122.  
  123.     With Me
  124.  
  125.         .ScaleMode = 3
  126.         .AutoRedraw = True
  127.         .BackColor = RGB(0, 0, 0)
  128.         .ForeColor = RGB(0, 255, 0)
  129.         
  130.     End With
  131.     
  132.     With Obj
  133.     
  134.         .Mass = 10 * POUNDS_TO_KG
  135.         .One_Over_Mass = 1 / .Mass
  136.         .Position.X = Me.ScaleWidth / 2
  137.         .Position.Y = 0 'Me.ScaleHeight / 2
  138.         .Velocity.X = 3
  139.         .Velocity.Y = 0
  140.         .Acceleration.X = 0
  141.         .Acceleration.Y = 0
  142.         .Force.Net.X = 0
  143.         .Force.Net.Y = Calculate_Gravitational_Force(.Mass, EARTH_GRAVITY) - Calculate_Air_Resistance(.Drag_Coefficient, AIR_DENSITY, .Area, .Velocity.Y)
  144.         .Scalar = 1000
  145.         .Elasticity = 0.7
  146.         .Friction_Coefficient = 0.7
  147.         .Drag_Coefficient = 0.47 '1000 for water
  148.         .Area = 1
  149.     
  150.     End With
  151.  
  152.     Time_Step = 1 / 1000
  153.  
  154.     Running = True
  155.  
  156.     QueryPerformanceFrequency Ticks_Per_Second
  157.     
  158.     Milliseconds = Time
  159.     
  160.     Neutral_Flag = True
  161.     
  162.     Game_Loop
  163.  
  164. End Sub
  165.  
  166. Private Sub Game_Loop()
  167.  
  168.     Do While Running = True
  169.     
  170.         DoEvents
  171.         
  172.         Lock_Framerate 60
  173.         
  174.         Cls
  175.         
  176.         Old_Position.X = Obj.Position.X
  177.         Old_Position.Y = Obj.Position.Y
  178.          
  179.         Delta_Time = Get_Elapsed_Time_Per_Frame
  180.         
  181.         If Delta_Time > 0.25 Then Delta_Time = 0.25
  182.         
  183.         Accumulator = Accumulator + Delta_Time
  184.         
  185.         While (Accumulator >= Time_Step)
  186.             
  187.             Accumulator = Accumulator - Time_Step
  188.             
  189.             Integrate2D Obj, Time_Step, FORTH_ORDER_RUNGE_KUTTA
  190.             
  191.             Time = Time + Time_Step
  192.             
  193.         Wend
  194.         
  195.         Check_Collision Obj
  196.         
  197.         Render
  198.  
  199.     Loop
  200.  
  201. End Sub
  202.  
  203. Private Function Calculate_Normal_Force(m As Double, g As Double) As Double
  204.  
  205.    Calculate_Normal_Force = m * g
  206.  
  207. End Function
  208.  
  209. Private Function Calculate_Frictional_Force(u As Double, N As Double) As Double
  210.  
  211.     Calculate_Frictional_Force = u * N
  212.  
  213. End Function
  214.  
  215. Private Function Calculate_Gravitational_Force(m As Double, g As Double) As Double
  216.  
  217.     Calculate_Gravitational_Force = m * g
  218.     
  219. End Function
  220.  
  221. Private Function Calculate_Air_Resistance(C As Double, p As Double, Area As Double, v As Double)
  222.     
  223.     'F = C*p*A*v�/2
  224.  
  225.     Calculate_Air_Resistance = (C * p * Area * (v * v)) * 0.5
  226.  
  227. End Function
  228.  
  229. Private Sub Lock_Framerate(Target_FPS As Long)
  230.  
  231.     Static Last_Time As Currency
  232.  
  233.     Dim Current_Time As Currency
  234.     
  235.     Dim FPS As Double
  236.     
  237.     Do
  238.  
  239.         QueryPerformanceCounter Current_Time
  240.     
  241.         FPS = Ticks_Per_Second / (Current_Time - Last_Time)
  242.     
  243.     Loop While (FPS > Target_FPS)
  244.     
  245.     QueryPerformanceCounter Last_Time
  246.  
  247. End Sub
  248.  
  249. Private Function Get_Elapsed_Time_Per_Frame() As Double
  250.  
  251.     Static Last_Time As Currency
  252.  
  253.     Static Current_Time As Currency
  254.  
  255.     QueryPerformanceCounter Current_Time
  256.     
  257.     Get_Elapsed_Time_Per_Frame = (Current_Time - Last_Time) / Ticks_Per_Second
  258.     
  259.     QueryPerformanceCounter Last_Time
  260.  
  261. End Function
  262.  
  263. Private Function Get_Elapsed_Seconds() As Double
  264.     
  265.     Dim Last_Time As Currency
  266.     
  267.     Dim Current_Time As Currency
  268.  
  269.     QueryPerformanceCounter Current_Time
  270.     
  271.     Get_Elapsed_Seconds = (Current_Time - Last_Time) / Ticks_Per_Second
  272.     
  273.     QueryPerformanceCounter Last_Time
  274.     
  275. End Function
  276.  
  277. Private Function Get_FPS(Optional ByVal Elapsed_Frames As Long = 1) As Long
  278.  
  279.     Static Last_Time As Currency
  280.  
  281.     Dim Current_Time As Currency
  282.     
  283.     QueryPerformanceCounter Current_Time
  284.     
  285.     Get_FPS = Int(Elapsed_Frames * Ticks_Per_Second / (Current_Time - Last_Time))
  286.     
  287.     QueryPerformanceCounter Last_Time
  288.     
  289. End Function
  290.  
  291. Private Sub Integrate2D(Obj As PHYSICS2D, dt As Double, Integrator As CONST_INTEGRATOR)
  292.  
  293.  
  294.     Dim Old_Position As POINT2D
  295.     Dim Old_Velocity As POINT2D
  296.     Dim Old_Acceleration As POINT2D
  297.     Dim Old_Angle As Double
  298.     Dim Old_Angular_Velocity As Double
  299.     Dim Old_Angular_Acceleration As Double
  300.  
  301.     Dim k1 As POINT2D, k2 As POINT2D, k3 As POINT2D, k4 As POINT2D
  302.     Dim l1 As VECTOR2D, l2 As VECTOR2D, l3 As VECTOR2D, l4 As VECTOR2D
  303.     
  304.     Dim m1 As Double, m2 As Double, m3 As Double, m4 As Double
  305.     Dim n1 As Double, n2 As Double, n3 As Double, n4 As Double
  306.     
  307.     With Obj
  308.  
  309.         .Acceleration.X = .Force.Net.X * .One_Over_Mass
  310.         .Acceleration.Y = .Force.Net.Y * .One_Over_Mass
  311.         
  312.         .Angular_Acceleration = .Torque.Net * .One_Over_Inertia
  313.         
  314.         Select Case Integrator
  315.         
  316.             Case FORWARD_EULER
  317.                 
  318.                 .Position.X = .Position.X + .Velocity.X * dt * .Scalar
  319.                 .Velocity.X = .Velocity.X + .Acceleration.X * dt
  320.             
  321.                 .Position.Y = .Position.Y + .Velocity.Y * dt * .Scalar
  322.                 .Velocity.Y = .Velocity.Y + .Acceleration.Y * dt
  323.                 
  324.                 .Angle = .Angle + .Angular_Velocity * dt
  325.                 .Angular_Velocity = .Angular_Velocity + .Angular_Acceleration * dt
  326.                 
  327.             Case SECOND_ORDER_EULER
  328.             
  329.                 .Position.X = .Position.X + .Velocity.X * dt + 0.5 * .Acceleration.X * dt * dt * .Scalar
  330.                 .Velocity.X = .Velocity.X + .Acceleration.X * dt
  331.             
  332.                 .Position.Y = .Position.Y + .Velocity.Y * dt + 0.5 * .Acceleration.Y * dt * dt * .Scalar
  333.                 .Velocity.Y = .Velocity.Y + .Acceleration.Y * dt
  334.                 
  335.                 .Angle = .Angle + .Angular_Velocity * dt + 0.5 * .Angular_Acceleration * dt * dt
  336.                 .Angular_Velocity = .Angular_Velocity + .Angular_Acceleration * dt
  337.             
  338.             Case VERLET
  339.             
  340.                 .Velocity.X = .Position.X - Old_Position.X + .Acceleration.X * dt * dt * .Scalar
  341.                 Old_Position.X = .Position.X
  342.                 .Position.X = .Position.X + .Velocity.X
  343.                 
  344.                 .Velocity.Y = .Position.Y - Old_Position.Y + .Acceleration.Y * dt * dt * .Scalar
  345.                 Old_Position.Y = .Position.Y
  346.                 .Position.Y = .Position.Y + .Velocity.Y
  347.                 
  348.                 .Angular_Velocity = .Angle - Old_Angle + .Angular_Acceleration * dt * dt
  349.                 Old_Angle = .Angle
  350.                 .Angle = .Angle + .Angular_Velocity
  351.                 
  352.             Case VELOCITY_VERLET
  353.                 
  354.                 Old_Acceleration.X = .Acceleration.X
  355.                 .Position.X = .Position.X + .Velocity.X * dt + 0.5 * Old_Acceleration.X * dt * dt * .Scalar
  356.                 .Velocity.X = .Velocity.X + 0.5 * (Old_Acceleration.X + .Acceleration.X) * dt
  357.             
  358.                 Old_Acceleration.Y = .Acceleration.Y
  359.                 .Position.Y = .Position.Y + .Velocity.Y * dt + 0.5 * Old_Acceleration.Y * dt * dt * .Scalar
  360.                 .Velocity.Y = .Velocity.Y + 0.5 * (Old_Acceleration.Y + .Acceleration.Y) * dt
  361.             
  362.                 Old_Angular_Acceleration = .Angular_Acceleration
  363.                 .Angle = .Angle + .Angular_Velocity * dt + 0.5 + Old_Angular_Acceleration * dt * dt
  364.                 .Angular_Velocity = .Angular_Velocity + 0.5 * (Old_Angular_Acceleration + .Angular_Acceleration) * dt
  365.             
  366.             Case SECOND_ORDER_RUNGE_KUTTA
  367.             
  368.                 k1.X = dt * .Velocity.X
  369.                 k1.Y = dt * .Velocity.Y
  370.                 l1.X = dt * .Acceleration.X
  371.                 l1.Y = dt * .Acceleration.Y
  372.                 
  373.                 k2.X = dt * (.Velocity.X + k1.X / 2)
  374.                 k2.Y = dt * (.Velocity.Y + k1.Y / 2)
  375.                 l2.X = dt * .Acceleration.X
  376.                 l2.Y = dt * .Acceleration.Y
  377.                 
  378.                 m1 = dt * .Angular_Velocity
  379.                 n1 = dt * .Angular_Acceleration
  380.                 
  381.                 m2 = dt * (.Angular_Velocity + m1 / 2)
  382.                 n2 = dt * .Angular_Acceleration
  383.                 
  384.                 .Position.X = .Position.X + k2.X * .Scalar
  385.                 .Position.Y = .Position.Y + k2.Y * .Scalar
  386.                 .Velocity.X = .Velocity.X + l2.X
  387.                 .Velocity.Y = .Velocity.Y + l2.Y
  388.                 
  389.                 
  390.                 .Angle = .Angle + m2
  391.                 .Angular_Velocity = .Angular_Velocity + n2
  392.             
  393.             Case THIRD_ORDER_RUNGE_KUTTA
  394.             
  395.                 k1.X = dt * .Velocity.X
  396.                 k1.Y = dt * .Velocity.Y
  397.                 l1.X = dt * .Acceleration.X
  398.                 l1.Y = dt * .Acceleration.Y
  399.                 
  400.                 k2.X = dt * (.Velocity.X + k1.X / 2)
  401.                 k2.Y = dt * (.Velocity.Y + k1.Y / 2)
  402.                 l2.X = dt * .Acceleration.X
  403.                 l2.Y = dt * .Acceleration.Y
  404.                 
  405.                 k3.X = dt * (.Velocity.X - k1.X + 2 * k2.X)
  406.                 k3.Y = dt * (.Velocity.Y - k1.Y + 2 * k2.Y)
  407.                 l3.X = dt * .Acceleration.X
  408.                 l3.Y = dt * .Acceleration.Y
  409.                 
  410.                 m1 = dt * .Angular_Velocity
  411.                 n1 = dt * .Angular_Acceleration
  412.                 
  413.                 m2 = dt * (.Angular_Velocity * m1 / 2)
  414.                 n2 = dt * .Angular_Acceleration
  415.                 
  416.                 m3 = dt * (.Angular_Velocity - m1 + 2 * m2)
  417.                 n3 = dt * .Angular_Acceleration
  418.                 
  419.                 .Position.X = .Position.X + k1.X * 1 / 6 + k2.X * 2 / 3 + k3.X * 1 / 6 * .Scalar
  420.                 .Position.Y = .Position.Y + k1.Y * 1 / 6 + k2.Y * 2 / 3 + k3.Y * 1 / 6 * .Scalar
  421.                 .Velocity.X = .Velocity.X + l1.X * 1 / 6 + l2.X * 2 / 3 + l3.X * 1 / 6
  422.                 .Velocity.Y = .Velocity.Y + l1.Y * 1 / 6 + l2.Y * 2 / 3 + l3.Y * 1 / 6
  423.                 
  424.                 .Angle = .Angle + m1 * 1 / 6 + m2 * 2 / 3 + m3 * 1 / 6
  425.                 .Angular_Velocity = .Angular_Velocity + n1 * 1 / 6 + n2 * 2 / 3 + n3 * 1 / 6
  426.                 
  427.             Case FORTH_ORDER_RUNGE_KUTTA
  428.             
  429.                 k1.X = dt * .Velocity.X
  430.                 k1.Y = dt * .Velocity.Y
  431.                 l1.X = dt * .Acceleration.X
  432.                 l1.Y = dt * .Acceleration.Y
  433.                 
  434.                 k2.X = dt * (.Velocity.X + k1.X / 2)
  435.                 k2.Y = dt * (.Velocity.Y + k1.Y / 2)
  436.                 l2.X = dt * .Acceleration.X
  437.                 l2.Y = dt * .Acceleration.Y
  438.                 
  439.                 k3.X = dt * (.Velocity.X + k2.X / 2)
  440.                 k3.Y = dt * (.Velocity.Y + k2.Y / 2)
  441.                 l3.X = dt * .Acceleration.X
  442.                 l3.Y = dt * .Acceleration.Y
  443.                 
  444.                 k4.X = dt * (.Velocity.X + k3.X)
  445.                 k4.Y = dt * (.Velocity.Y + k3.Y)
  446.                 l4.X = dt * .Acceleration.X
  447.                 l4.Y = dt * .Acceleration.Y
  448.                 
  449.                 m1 = dt * .Angular_Velocity
  450.                 n1 = dt * .Angular_Acceleration
  451.                 
  452.                 m2 = dt * (.Angular_Velocity + m1 / 2)
  453.                 n2 = dt * .Angular_Acceleration
  454.                 
  455.                 m3 = dt * (.Angular_Velocity + m2 / 2)
  456.                 n3 = dt * .Angular_Acceleration
  457.                 
  458.                 m4 = dt * (.Angular_Velocity + m3)
  459.                 n4 = dt * .Angular_Acceleration
  460.                  
  461.                 .Position.X = .Position.X + k1.X / 6 + k2.X / 3 + k3.X / 3 + k4.X / 6 * .Scalar
  462.                 .Position.Y = .Position.Y + k1.Y / 6 + k2.Y / 3 + k3.Y / 3 + k4.Y / 6 * .Scalar
  463.                 .Velocity.X = .Velocity.X + l1.X / 6 + l2.X / 3 + l3.X / 3 + l4.X / 6
  464.                 .Velocity.Y = .Velocity.Y + l1.Y / 6 + l2.Y / 3 + l3.Y / 3 + l4.Y / 6
  465.                 
  466.                 .Angle = .Angle + m1 / 6 + m2 / 3 + m3 / 3 + m4 / 6
  467.                 .Angular_Velocity = .Angular_Velocity + n1 / 6 + n2 / 3 + n3 / 3 + n4 / 6
  468.                 
  469.         End Select
  470.         
  471.     End With
  472.  
  473. End Sub
  474.  
  475.  
  476. Private Sub Clear()
  477.  
  478.     Me.Cls
  479.  
  480. End Sub
  481.  
  482. Private Function Check_Collision(Obj As PHYSICS2D)
  483.     
  484.     Const MIN As Double = 0.4
  485.     
  486.     With Obj
  487.     
  488.         Dim I As Boolean
  489.          
  490.         If .Position.X - Old_Position.X > 0 Then
  491.             
  492.             I = True
  493.             
  494.         ElseIf .Position.X - Old_Position.X < 0 Then
  495.         
  496.             I = False
  497.             
  498.         End If
  499.     
  500.         If .Position.Y >= 175 Then
  501.  
  502.             .Position.Y = 175
  503.             .Velocity.Y = .Velocity.Y * -.Elasticity
  504.             
  505.             If .Velocity.Y >= 0 Then
  506.             
  507.                 If .Velocity.Y <= MIN Then
  508.                 
  509.                     .Velocity.Y = 0
  510.                     .Force.Net.Y = 0
  511.                 
  512.                 End If
  513.                 
  514.             Else
  515.             
  516.                 If .Velocity.Y >= -MIN Then
  517.                 
  518.                     .Velocity.Y = 0
  519.                     .Force.Net.Y = 0
  520.                 
  521.                 End If
  522.             
  523.             End If
  524.  
  525.             If I = True Then
  526.             
  527.                 .Force.Net.X = -Calculate_Frictional_Force(.Friction_Coefficient, Calculate_Normal_Force(.Mass, EARTH_GRAVITY))
  528.             
  529.                 If .Velocity.X <= MIN Then
  530.                 
  531.                     .Velocity.X = 0
  532.                     .Force.Net.X = 0
  533.                 
  534.                 End If
  535.             
  536.             Else
  537.             
  538.                 .Force.Net.X = Calculate_Frictional_Force(.Friction_Coefficient, Calculate_Normal_Force(.Mass, EARTH_GRAVITY))
  539.                 
  540.                 If .Velocity.X >= -MIN Then
  541.                 
  542.                     .Velocity.X = 0
  543.                     .Force.Net.X = 0
  544.                    
  545.                 End If
  546.                 
  547.             End If
  548.                 
  549.             
  550.         Else
  551.         
  552.             .Force.Net.X = 0
  553.             
  554.         End If
  555.         
  556.         If .Position.X >= 275 Then
  557.  
  558.             .Position.X = 275
  559.             .Velocity.X = .Velocity.X * -.Elasticity
  560.             
  561.             .Force.Net.Y = EARTH_GRAVITY + Calculate_Frictional_Force(.Friction_Coefficient, Calculate_Normal_Force(.Mass, EARTH_GRAVITY)) - Calculate_Air_Resistance(.Drag_Coefficient, AIR_DENSITY, .Area, .Velocity.Y)
  562.             
  563.         Else
  564.         
  565.             .Force.Net.Y = Calculate_Gravitational_Force(.Mass, EARTH_GRAVITY) - Calculate_Air_Resistance(.Drag_Coefficient, AIR_DENSITY, .Area, .Velocity.Y)
  566.             
  567.         End If
  568.         
  569.         If .Position.X <= 30 Then
  570.             
  571.             .Position.X = 30
  572.             .Velocity.X = .Velocity.X * -.Elasticity
  573.             
  574.             .Force.Net.Y = EARTH_GRAVITY + Calculate_Frictional_Force(.Friction_Coefficient, Calculate_Normal_Force(.Mass, EARTH_GRAVITY)) - Calculate_Air_Resistance(.Drag_Coefficient, AIR_DENSITY, .Area, .Velocity.Y)
  575.             
  576.         Else
  577.         
  578.             .Force.Net.Y = Calculate_Gravitational_Force(.Mass, EARTH_GRAVITY) - Calculate_Air_Resistance(.Drag_Coefficient, AIR_DENSITY, .Area, .Velocity.Y)
  579.             
  580.         End If
  581.         
  582.     End With
  583.  
  584. End Function
  585.  
  586. Private Sub Render()
  587.     
  588.     On Error Resume Next
  589.     
  590.     Dim X As Double, Y As Double
  591.     
  592.     X = Obj.Position.X
  593.     Y = Obj.Position.Y
  594.     
  595.     Circle (X, Y), 15, RGB(0, 255, 0)
  596.     
  597.     Line (0, 190)-(Me.ScaleWidth, 190), RGB(0, 255, 0)
  598.  
  599. End Sub
  600.  
  601. Private Sub Close_Program()
  602.  
  603.     Running = False
  604.     
  605.     Unload Me
  606.     
  607.     End
  608.     
  609. End Sub
  610.  
  611. Private Sub Form_Activate()
  612.  
  613.     Main
  614.  
  615. End Sub
  616.  
  617.  
  618. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  619.  
  620.     Running = False
  621.  
  622. End Sub
  623.  

Ответить

Номер ответа: 5
Автор ответа:
 AWP



ICQ: 345685652 

Вопросов: 96
Ответов: 1212
 Web-сайт: xawp.narod.ru
 Профиль | | #5
Добавлено: 22.07.09 02:54
А что физику не изучали? Гравицапа в любом языке одинаково делаецца!

Ответить

Номер ответа: 6
Автор ответа:
 VβÐUηìt



Вопросов: 246
Ответов: 3333
 Web-сайт: смекаешь.рф
 Профиль | | #6
Добавлено: 22.07.09 10:22
UU, ты тут физичезкий движог описл или что? А то я от такой прорвы кода на такую простую задачу малость офигел. :) Объясни плиз.

Ответить

Номер ответа: 7
Автор ответа:
 ☺♣FIO♣☺



Вопросов: 35
Ответов: 160
 Профиль | | #7 Добавлено: 22.07.09 10:46
мдааа... Действительно, многовато чёто... есть попроще?

Ответить

Номер ответа: 8
Автор ответа:
 Sneaks



Вопросов: 9
Ответов: 84
 Профиль | | #8 Добавлено: 22.07.09 11:00
омг
есть позиция объекта, есть вектор. Вектор изменяется с воздействием сил тяжести+сопротивление, каждый раз объект сдвигать на вектор. При столкновении ставить обратный вектор. В чем сложность то?

Ответить

Номер ответа: 9
Автор ответа:
 VβÐUηìt



Вопросов: 246
Ответов: 3333
 Web-сайт: смекаешь.рф
 Профиль | | #9
Добавлено: 22.07.09 13:34
'Сугубо тупо без векторофф, сопротивлений воздуха, эластичности и прочих как ты считаешь "сложностей":
  1.  
  2. Private Type obj
  3. r  as long
  4. X as long
  5. Y as long
  6. vx as long
  7. vy as long
  8. end Type
  9. dim shar as obj
  10. Sub Timer1_Timer
  11. with shar
  12. .y =.y +.vy
  13. .x =.x +.vx
  14. if.y > scaleheight - .r then .y = .scaleheight - .r: .vy = .vy * -0.5
  15. .vy = .vy + 10
  16. if abs(.vy) > 100 then .vy = 100 * sgn(.vy)
  17. end with
  18. End Sub

Ответить

Номер ответа: 10
Автор ответа:
 ☺♣FIO♣☺



Вопросов: 35
Ответов: 160
 Профиль | | #10 Добавлено: 22.07.09 14:16
scaleheight - что это?

Ответить

Номер ответа: 11
Автор ответа:
 VβÐUηìt



Вопросов: 246
Ответов: 3333
 Web-сайт: смекаешь.рф
 Профиль | | #11
Добавлено: 22.07.09 20:13
Высота рабочей области формы. И вообще, дуй в гугл.

Ответить

Номер ответа: 12
Автор ответа:
 ☺♣FIO♣☺



Вопросов: 35
Ответов: 160
 Профиль | | #12 Добавлено: 23.07.09 09:53
в гугле я не силач...

Ответить

Номер ответа: 13
Автор ответа:
 VβÐUηìt



Вопросов: 246
Ответов: 3333
 Web-сайт: смекаешь.рф
 Профиль | | #13
Добавлено: 23.07.09 10:21
Дык накачайся

Ответить

Номер ответа: 14
Автор ответа:
 AWP



ICQ: 345685652 

Вопросов: 96
Ответов: 1212
 Web-сайт: xawp.narod.ru
 Профиль | | #14
Добавлено: 23.07.09 22:58
Предлагаю сделать модель падающего шара с учётом:
 - Центра тяжести
 - Плотности воздуха
 - Плотности шара
 - Коэффициента трения поверхности
 - Коэффициента упругости шара

Ответить

Номер ответа: 15
Автор ответа:
 Ra$cal



ICQ: 8068014 

Вопросов: 18
Ответов: 817
 Web-сайт: www.rascalspb.narod.ru
 Профиль | | #15
Добавлено: 23.07.09 23:36
а как же учет гравитации луны(а соответственно и ее фазы)? без этого никак нельзя

Ответить

Страница: 1 | 2 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам