home *** CD-ROM | disk | FTP | other *** search
/ MORE WinGames / WINGAMES.iso / winpool / goodies.c < prev    next >
C/C++ Source or Header  |  1992-11-29  |  3KB  |  104 lines

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