home *** CD-ROM | disk | FTP | other *** search
/ PC World 2006 July & August / PCWorld_2006-07-08_cd.bin / temacd / planearcade / planearcade.exe / Tank3.bmp / fireball.cpp < prev    next >
C/C++ Source or Header  |  2004-09-20  |  3KB  |  130 lines

  1.  
  2. #include "main.h"
  3.  
  4. //kontruktor
  5. //-----------------------------------------------------------------
  6. FIREBALL::FIREBALL()
  7. {
  8.  
  9.     //inicializacia segmentov
  10.     for (int i=0;i<FireBall_Max;i++)
  11.     {
  12.         Segment[i].Pos = Get3D(0.0f,0.0f,0.0f);
  13.         Segment[i].Active = false;
  14.         Segment[i].Time = 0.0f;
  15.     }
  16.     
  17.     //inicializacia vlastnosti
  18.     SRCColor = GetColor(1.0f,1.0f,1.0f,1.0f);
  19.     DSTColor = GetColor(0.0f,0.0f,0.0f,0.0f);
  20.     SRCRot = Get3D(0.0f,0.0f,0.0f);
  21.     DSTRot = Get3D(0.0f,0.0f,0.0f);
  22.     RandRotation = false;
  23.     SRCScale = Get3D(1.0f,1.0f,1.0f);
  24.     DSTScale = Get3D(5.0f,5.0f,5.0f);
  25.     Time = 1000.0f;
  26.  
  27. }
  28.  
  29. //inicializacia - load modelu
  30. //-----------------------------------------------------------------
  31. void FIREBALL::Initialize(char *ModelFileName,char *TextureFileName,COLOR TColor)
  32. {
  33.     Model.Lighting = false;
  34.     Model.SmoothShading = false;
  35.     Model.Normals = false;
  36.     Model.Color = GetColor(1,0,0,0);
  37.     Model.InitializeAse(1,ModelFileName);
  38.     Model.LoadAse(0,ModelFileName);
  39.     Model.LoadTexture(TextureFileName,TColor);
  40.     Model.Lighting = true;
  41.     
  42. }
  43.  
  44. //render & process
  45. //-----------------------------------------------------------------
  46. void FIREBALL::Refresh()
  47. {
  48.     float Int;
  49.  
  50.     for (int i=0;i<FireBall_Max;i++)
  51.     {
  52.         if (Segment[i].Active == false)
  53.             continue;
  54.         
  55.         //casovac
  56.         Segment[i].Time += PowerTime(1.0f);
  57.         if (Segment[i].Time > Time)
  58.         {
  59.             Segment[i].Active = false;
  60.             continue;
  61.         }
  62.         
  63.         //interpolant
  64.         Int = Segment[i].Time/Time;
  65.         if (Int > 1.0f) Int = 1.0f;
  66.         if (Int < 0.0f) Int = 0.0f;
  67.  
  68.         //render
  69.         Model.Sca.X = SRCScale.X + ((DSTScale.X-SRCScale.X)*Int);
  70.         Model.Sca.Y = SRCScale.Y + ((DSTScale.Y-SRCScale.Y)*Int);
  71.         Model.Sca.Z = SRCScale.Z + ((DSTScale.Z-SRCScale.Z)*Int);
  72.  
  73.         if (RandRotation)
  74.         {
  75.             Model.Rot = Segment[i].Rot;
  76.         }
  77.         else
  78.         {
  79.             Model.Rot.X = SRCRot.X + ((DSTRot.X-SRCRot.X)*Int);
  80.             Model.Rot.Y = SRCRot.Y + ((DSTRot.Y-SRCRot.Y)*Int);
  81.             Model.Rot.Z = SRCRot.Z + ((DSTRot.Z-SRCRot.Z)*Int);
  82.         }
  83.  
  84. //        Model.Color.A = SRCColor.A + ((DSTColor.A-SRCColor.A)*Int);
  85. //        Model.Color.R = SRCColor.R + ((DSTColor.R-SRCColor.R)*Int);
  86. //        Model.Color.G = SRCColor.G + ((DSTColor.G-SRCColor.G)*Int);
  87. //        Model.Color.B = SRCColor.B + ((DSTColor.B-SRCColor.B)*Int);
  88.  
  89.         Model.SetMaterial(GetMaterial(GetColor(0,0,0,0),
  90.                                       GetColor(0,0,0,0),
  91.                                       GetColor(0,0,0,0),
  92.                                       GetColor(SRCColor.A + ((DSTColor.A-SRCColor.A)*Int),
  93.                                                SRCColor.R + ((DSTColor.R-SRCColor.R)*Int),
  94.                                                SRCColor.G + ((DSTColor.G-SRCColor.G)*Int),
  95.                                                SRCColor.B + ((DSTColor.B-SRCColor.B)*Int)),
  96.                                       0.0f));
  97.         Model.Pos = Segment[i].Pos;
  98.  
  99.         Engine.SetZwrite(false);
  100.             Model.Render();
  101.         Engine.SetZwrite(true);
  102.  
  103.     }
  104.  
  105. }
  106.  
  107. //vypustenie segmentu
  108. //-----------------------------------------------------------------
  109. void FIREBALL::Spawn(VECTOR3D Pos)
  110. {
  111.     for (int i=0;i<FireBall_Max;i++)
  112.     {
  113.         if (Segment[i].Active == true)
  114.             continue;
  115.         
  116.         Segment[i].Active = true;
  117.         Segment[i].Pos = Pos;
  118.         Segment[i].Time = 0.0f;
  119.  
  120.         if (RandRotation)
  121.         {
  122.             Segment[i].Rot.X = RandomMinMax(-3.14f,3.14f);
  123.             Segment[i].Rot.Y = RandomMinMax(-3.14f,3.14f);
  124.             Segment[i].Rot.Z = RandomMinMax(-3.14f,3.14f);
  125.         }
  126.  
  127.         break;
  128.     }
  129.  
  130. }