/* * (C) COPYRIGHT Vincent S. Cojot and others 1996-1997 * All Rights Reserved * Licensed Materials - Property of Vincent S. Cojot and others. * Use, duplication or disclosure restricted by Vincent S. Cojot. */ #include #include #include #include #include #include #include "defines.h" #include "operations.h" #ifdef USING_MESA #include #else #include #endif #ifndef PI #define PI 3.141592653895 #endif /*****************************************************************\ * operations.c * * * * Description: Ce fichier contient deux fonctions: Normale1() * * et ProduitScalaire(). * * * * Auteurs: Barbeau, Anik, 50606 * * Chiniara, Patrice, 52233 * * Cojot, Vincent, 50945 * * * * Date: Montreal, le 12 fevrier 1996 * * * \*****************************************************************/ /*****************************************************************\ * Normale1() * * * * Description: Cette fonction recoit en parametre les deux * * vecteurs (v1i,v1j) et (v2i,v2j) et retourne le * * vecteur normal (normalise) (vi,vj). * * * * Auteurs: Barbeau, Anik, 50606 * * Chiniara, Patrice, 52233 * * Cojot, Vincent, 50945 * * * * Date: Montreal, le 12 fevrier 1996 * * * \*****************************************************************/ void Normale1 (float v1i, float v1j, float v2i, float v2j, float *vi, float *vj) { float den, tmp, v1, v2; v1 = v1i + v2i; v2 = v1j + v2j; *vi = v1 * v1; *vj = v2 * v2; tmp = *vi +(*vj); den = sqrt(tmp); *vi = v1 / den; *vj = v2 / den; } /*****************************************************************\ * ProduitScalaire() * * * * Description: Cette fonction recoit en parametre les deux * * vecteurs (v1i,v1j) et (v2i,v2j) et retourne le * * produit scalaire. * * * * Auteurs: Barbeau, Anik, 50606 * * Chiniara, Patrice, 52233 * * Cojot, Vincent, 50945 * * * * Date: Montreal, le 12 fevrier 1996 * * * \*****************************************************************/ float ProduitScalaire (float v1i, float v1j, float v2i, float v2j) { float va,vb, vc, vd; va = v1i / sqrt (v1i*v1i + v1j*v1j); vb = v1j / sqrt (v1i*v1i + v1j*v1j); vc = v2i / sqrt (v2i*v2i + v2j*v2j); vd = v2j / sqrt (v2i*v2i + v2j*v2j); va *= vc; vb *= vb; va += vb; return va; } /*****************************************************************/ /* Initialisation des objets simules. */ /*****************************************************************/ GLvoid SimulationInit(GLvoid) { GLint i; for (i=0;i<5;i++) { while ( FindStartupPosition() ); OneTank.Posx = RandomscenePosx; OneTank.Posz = RandomscenePosz; OneTank.Angle = RandomsceneAngle; InsertTank(OneTank); } } /*****************************************************************/ /* Deplacement des objets simules. */ /*****************************************************************/ GLvoid SimulationRun(GLvoid) { GLint i; /* Il faudrait ajouter un peu d'intelligence artificielle */ /* car pour l'instant, les tanks enemis ne font que tourner */ /* sur eux-memes..*/ for (i=0;i count ) { if ( !(strcmp(argv[count],"-net")) && !(user_network) ) { user_network = 1; strcpy(network_group,argv[count+1]); count += 2; } else if ( !(strcmp(argv[count],"-port")) && !(user_port) ) { user_port = 1; network_port = atoi(argv[count+1]); count += 2; } else if ( !(strcmp(argv[count],"-delay")) && !(user_packet_delay) ) { user_packet_delay = 1; network_delay = atol(argv[count+1]); count += 2; } else { count++; } } if ( (argc > 1) && (user_network == 0) && (user_port == 0) && (user_packet_delay == 0) ) { PrintCorrectArgs(argc,argv); } else { if (user_network) { printf("Using subnet %s .\n",network_group); } if (user_port) { printf("Using port %i .\n",network_port); } if (user_packet_delay) { printf("Using network delay %li .\n",network_delay); } } } /*****************************************************************/ /* Si le nombre d'arguments n'est pas correct ou si erreur */ /*****************************************************************/ GLvoid PrintCorrectArgs(int argc,char *argv[]) { printf("\nIncorrect startup parameters specified.\n"); printf("Please use : %s", argv[0]); printf(" -net XXX.XXX.XXX.XXX"); printf(" -port port_number"); printf(" -delay network_delay\n"); printf("Set subnet for network gaming, example: -net %s (Default)\n" , network_group); printf("Set port between 1024 and 32768, example: -port %i (Default)\n" , network_port); printf("Set delay in microseconds, example: -delay %li (Default)\n" , network_delay); exit(1); }