home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xpool-10.zip / Xpool / goodies.c < prev    next >
C/C++ Source or Header  |  1992-05-26  |  3KB  |  103 lines

  1.  
  2. /* I. ARIT 1992 Hidirbeyli,AYDIN,TR.  09400
  3.                 Golden,    CO,   USA. 80401
  4.  
  5.  
  6.   Copyright (C) 1992 Ismail ARIT
  7.  
  8.   This file  is distributed in the hope that it will be useful,
  9.   but without any warranty.  No author or distributor accepts
  10.   responsibility to anyone for the consequences of using it or for
  11.   whether it serves any particular purpose or works at all.
  12.  
  13.  
  14.   Everyone is granted permission to copy, modify and redistribute
  15.   this file under the following conditions:
  16.  
  17.      Permission is granted to anyone to make or distribute copies
  18.      of the source code, either as received or modified, in any
  19.      medium, provided that all copyright notices, permission and
  20.      nonwarranty notices are preserved, and that the distributor
  21.      grants the recipient permission for further redistribution as
  22.      permitted by this document.
  23.      No part of this program can be used in any commercial product.
  24.  
  25.  
  26. */
  27.  
  28.  
  29. #include <stdio.h>
  30. #include <math.h>
  31.  
  32. #include "definition.h"
  33.  
  34.  
  35. Distance ThisMuch;
  36.  
  37.  
  38. Distance * DistanceChecker_Between (Ball * ThisBall, Ball * ThatBall) {
  39.  
  40.     if ((ThisBall -> In) && (ThatBall -> In)) {
  41.     ThisMuch.x = ThisBall -> CurrentL.x - ThatBall -> CurrentL.x;
  42.     ThisMuch.y = ThisBall -> CurrentL.y - ThatBall -> CurrentL.y;
  43.     ThisMuch.amount = (ThisBall -> radius + ThatBall -> radius) -
  44.         sqrt ((ThisMuch.x * ThisMuch.x) + (ThisMuch.y * ThisMuch.y));    }
  45.     else { 
  46.         ThisMuch.x = 0.0000000;
  47.         ThisMuch.y = 0.0000000;
  48.         ThisMuch.amount = 0.000000;
  49.                 }
  50. /*
  51. ThisBall -> NeedOneMoreDrawing = ((ThisMuch.amount +6 )>0)? YES : NO;
  52. ThatBall -> NeedOneMoreDrawing = ((ThisMuch.amount +6 )>0)? YES : NO;
  53. */
  54.  
  55.     return (&ThisMuch);
  56. };
  57.  
  58.  
  59. Force ForceToApply;
  60.  
  61. void
  62. Force_ToObject (Ball * first, Distance * TheirDistance, int type) {
  63.     double  theForce,
  64.             hip;
  65.     double  radian;
  66.  
  67.  
  68.  
  69.     /* let 's create force normal to the contact surface */
  70.     theForce = first -> kConstant * TheirDistance -> amount;
  71. /*
  72.     dprintf (" total %f  k %f d %f \n", theForce, first -> kConstant, TheirDistance -> amount);
  73.     dprintf (" d->x %f d->y %f \n", TheirDistance -> x, TheirDistance -> x);
  74. */
  75.     /* let 's calculate x,y componets */
  76.     hip = sqrt ((TheirDistance -> x * TheirDistance -> x) +
  77.         (TheirDistance -> y * TheirDistance -> y));
  78.  
  79.     ForceToApply.x = theForce * TheirDistance -> x / hip;
  80.     ForceToApply.y = theForce * TheirDistance -> y / hip;
  81.  
  82.  
  83.     if (type == ACTION) {
  84.     ForceToApply.x *= -1;
  85.     /* reaction to the fists ball */
  86.     ForceToApply.y *= -1;
  87.     }
  88.  
  89. /*
  90.     dprintf (" # %d  x %f y %f  fx %f  fy %f  \n", first -> MyID,
  91.         first -> CurrentL.x,
  92.         first -> CurrentL.y,
  93.         first -> CurrentF.x,
  94.         first -> CurrentF.y);
  95.  
  96.     dprintf ("  fx %f  fy %f  \n", ForceToApply.x, ForceToApply.y);
  97. */
  98.     first -> UpdateForce (first, &ForceToApply);
  99.  
  100.  
  101.  
  102. };
  103.