[Feature Request]Ooh

Discuss all aspects of editing for ZDoom.
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Postby Lexus Alyus » Wed Jan 05, 2005 11:29 am

Urm, what does randy have to say about this?

:twisted:
User avatar
Lexus Alyus
One day, I may actually release something...
 
Joined: 15 Jul 2003
Location: Nottingham, UK

Postby Chilvence » Wed Jan 05, 2005 11:53 am

Well, Randy hasn't said anything yet :)

Randy, its there, it works to the best of my knowledge, and if you want it help yourself. Unfortunately it doesnt look very good without full bright, and I can't make enough sense of the particle rendering code to add that myself (though I'll have another go tonight).

Like the railgun, it does have to be used sparingly, but I think it would make a neat effect for wad authors to be able to use. It can also work well with weapons because it always goes in a straight line overall.
User avatar
Chilvence
I had been waiting for Doomscript....
 
Joined: 11 Aug 2003

Postby Chilvence » Wed Jan 05, 2005 4:27 pm

updated, worked out my my fork ends were not working and added them back in (I wasnt properly converting from float to int)

Code: Select allExpand view
particle_t *LightningParticle (int ttl)
{
   particle_t *particle = NewParticle ();

   if (particle) {
      fixed_t *val = &particle->velx;

      particle->trans = 255;   // fully opaque
      particle->ttl = ttl;
      particle->fade = 0;
   }
   return particle;
}

void P_LightningParticle (vec3_t pos, int size)
{
      particle_t *h = LightningParticle (2);

      if (!h)
         return;

      h->size = (size*2)+1;
      h->x = FLOAT2FIXED(pos[0]);
      h->y = FLOAT2FIXED(pos[1]);
      h->z = FLOAT2FIXED(pos[2]);
      h->color = 193;
      h->trans = 64;
      h->fade = 32;

      particle_t *p = LightningParticle (2);

      if (!p)
         return;

      p->size = size;
      p->x = FLOAT2FIXED(pos[0]);
      p->y = FLOAT2FIXED(pos[1]);
      p->z = FLOAT2FIXED(pos[2]);
      p->color = 168;
}

void P_ConnectLightning (vec3_t start, vec3_t end)
{
   float length;
   int steps, i;

   vec3_t step, dir, pos;

   VectorSubtract (end, start, dir);
   length = VectorLength (dir);
   steps = (int)(length);

   if (length){length = 1 / length;}else{return;}

   VectorScale2 (dir, length);
   VectorScale (dir, 1, step);
   VectorCopy (start, pos);

   int div = 128-M_Random()*2000;
   for (i = steps; i; i--)
   {
      //we'll leave out the halo effect for now...
      P_LightningParticle(pos, 6);
      VectorAdd (pos, step, pos);
   }

}

void P_ForkEnd (vec3_t start, vec3_t dir)
{
   int i;

   vec3_t pos;

   VectorCopy (start, pos);
   VectorScale2(dir, 0.5f);
   float size = 6.0;
   float scale;

   for (i = 30; i; i--)
   {   
      scale = float(i)/float(30);
      size = 6.0f*scale;
      P_LightningParticle(pos, int(size));
      VectorAdd (pos, dir, pos);
   }

}

void P_DrawLightning (vec3_t start, vec3_t end)
{
   float length;
   int steps, i;

   vec3_t step, dir, pos;

   VectorSubtract (end, start, dir);
   length = VectorLength (dir);
   steps = (int)(length);

   if (length){length = 1 / length;}else{return;}


   vec3_t linepos; //where the real hitscan trace would be
   vec3_t linestep; //step to follow the imaginary hitscan line
   vec3_t kludge;  //used for measuring the distance between the current arc and the line
   vec3_t connect; //point from which to connect one arc to the next

   VectorScale2 (dir, length);
   VectorScale (dir, 1, step);
   VectorCopy (start, pos);
   VectorCopy (start, linepos);
   VectorCopy (start, connect);
   VectorCopy (step, linestep);
   VectorScale2 (step, 0.2f); //shorten the ligtning arcs a little bit...

   //arc amount, x, y, and z
   //I am assuming M_Random gives a number between 0 and 255, I hope this is correct)
   int ax = 128-M_Random();
   int ay = 128-M_Random();
   int az = 128-M_Random();

   for (i = steps; i; i--)
   {
      VectorSubtract (pos, linepos, kludge);
         if( VectorLength (kludge) > 30) //if the lightning deviates too far
         {
            //draw a line between the last closest position of the lightning to the hitscan line
            //and the new arc start position(which is the hitscan line itself)
            P_ConnectLightning(connect, linepos);
            P_ForkEnd(pos, step);
            //...
   
            VectorCopy(linepos, pos); // then reset the lightning trail to the hitscan line
            VectorCopy(linestep, step);
            
         }
         else if(VectorLength (kludge) < 12 ) //when the arc deviates more than 12 units, save this position
         {
            VectorCopy(pos, connect);
         }

      //halo before main arc so it is rendered first

      P_LightningParticle(pos, 6);

      //direction change: in effect this just generates a random vector and adds it to the arc line
      //this can potentially compress or extend the arc, but ultimately it doesnt matter since the
      //connector joins the arcs together, and we get free forks as a side effect without even
      //needing to calculate them

      if (M_Random() < 200)//add some randomness to the direction change
      {
         ax = (M_Random()-128)*50;
         ay = (M_Random()-128)*50;
         az = (M_Random()-128)*50;
      }

      float tempx = FIXED2FLOAT(ax);
      float tempy = FIXED2FLOAT(ay);
      float tempz = FIXED2FLOAT(az);
      
      step[0] += tempx;
      step[1] += tempy;
      step[2] += tempz;

      VectorAdd (pos, step, pos);
      VectorAdd (linepos, linestep, linepos);
   }
}
User avatar
Chilvence
I had been waiting for Doomscript....
 
Joined: 11 Aug 2003

Previous

Return to Editing (Archive)

Who is online

Users browsing this forum: Yandex [Bot] and 1 guest