#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <float.h>
#include "demo.h"
#include "3dgfx.h"
#include "vmath.h"
static int init(void)
{
- int i;
+ int i, j, numpt = 0;
gen_sphere_mesh(&sphmesh, 1.0f, 12, 6);
return -1;
}
- for(i=0; i<NSPAWNPOS; i++) {
- spawnpos[i] = spawndir[i] = sphrand(1.0f);
+ while(numpt < NSPAWNPOS) {
+ float best_dist = -1.0f;
+ for(i=0; i<100; i++) {
+ vec3_t pos = sphrand(1.0f);
+
+ float mindist = FLT_MAX;
+ for(j=0; j<numpt; j++) {
+ float dx = pos.x - spawnpos[i].x;
+ float dy = pos.y - spawnpos[i].y;
+ float dz = pos.z - spawnpos[i].z;
+ float dsq = dx * dx + dy * dy + dz * dz;
+ if(dsq < mindist) {
+ mindist = dsq;
+ }
+ }
+
+ if(mindist > best_dist) {
+ spawnpos[numpt] = pos;
+ best_dist = mindist;
+ }
+ }
+
+ spawndir[numpt] = spawnpos[numpt];
+ ++numpt;
}
return 0;
if(opt.sball) {
memcpy(hball.xform, sball_matrix, 16 * sizeof(float));
+
+ hball.pos.x = hball.xform[12];
+ hball.pos.y = hball.xform[13];
+ hball.pos.z = hball.xform[14];
} else {
if(mouse_bmask & MOUSE_BN_MIDDLE) {
hball.pos.x += mouse_dx * 0.05;
struct particle *p = palloc();
float *mat = hb->xform;
vec3_t pos = spawnpos[i];
+ vec3_t dir = spawndir[i];
p->pos.x = mat[0] * pos.x + mat[4] * pos.y + mat[8] * pos.z + mat[12];
p->pos.y = mat[1] * pos.x + mat[5] * pos.y + mat[9] * pos.z + mat[13];
p->pos.z = mat[2] * pos.x + mat[6] * pos.y + mat[10] * pos.z + mat[14];
- p->vel = spawndir[i];
+ p->vel.x = mat[0] * dir.x + mat[4] * dir.y + mat[8] * dir.z;
+ p->vel.y = mat[1] * dir.x + mat[5] * dir.y + mat[9] * dir.z;
+ p->vel.z = mat[2] * dir.x + mat[6] * dir.y + mat[10] * dir.z;
p->life = HAIR_LENGTH;
p->next = hb->plist[i];