+ else
+ {
+ if (b->entity == cl.viewentity)
+ Matrix4x4_CreateFromQuakeEntity(&matrix, r->origin[0], r->origin[1], r->origin[2] + 16, cl.viewangles[0], cl.viewangles[1], cl.viewangles[2], 1);
+ else
+ Matrix4x4_CreateFromQuakeEntity(&matrix, r->origin[0], r->origin[1], r->origin[2] + 16, r->angles[0], r->angles[1], r->angles[2], 1);
+ Matrix4x4_Transform(&matrix, b->relativestart, b->start);
+ Matrix4x4_Transform(&matrix, b->relativeend, b->end);
+ }
+ }
+
+ if (b->lightning)
+ {
+ if (cl_beams_lightatend.integer)
+ CL_AllocDlight (NULL, b->end, 200, 0.3, 0.7, 1, 0, 0);
+ if (cl_beams_polygons.integer)
+ continue;
+ }
+
+ // calculate pitch and yaw
+ VectorSubtract (b->end, b->start, dist);
+
+ if (dist[1] == 0 && dist[0] == 0)
+ {
+ yaw = 0;
+ if (dist[2] > 0)
+ pitch = 90;
+ else
+ pitch = 270;
+ }
+ else
+ {
+ yaw = (int) (atan2(dist[1], dist[0]) * 180 / M_PI);
+ if (yaw < 0)
+ yaw += 360;
+
+ forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
+ pitch = (int) (atan2(dist[2], forward) * 180 / M_PI);
+ if (pitch < 0)
+ pitch += 360;
+ }
+
+ // add new entities for the lightning
+ VectorCopy (b->start, org);
+ d = VectorNormalizeLength(dist);
+ while (d > 0)
+ {
+ ent = CL_NewTempEntity ();
+ if (!ent)
+ return;
+ //VectorCopy (org, ent->render.origin);
+ ent->render.model = b->model;
+ ent->render.effects = EF_FULLBRIGHT;
+ //ent->render.angles[0] = pitch;
+ //ent->render.angles[1] = yaw;
+ //ent->render.angles[2] = rand()%360;
+ Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, org[0], org[1], org[2], -pitch, yaw, lhrandom(0, 360), 1);
+ Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
+ CL_BoundingBoxForEntity(&ent->render);
+ VectorMA(org, 30, dist, org);
+ d -= 30;