Example #1
0
	//-----------------------------------------------------------------//
	bool clumped_bspline(const fvtxs& src, int lod, fvtxs& dst)
	{
		int size = (int)src.size();
		if(size < 4) return false;

		dst.clear();
		for(int n = -3; n < (size + 1); ++n) {
			for(int i = 0; i < lod; ++i) {
				float t = static_cast<float>(i) / static_cast<float>(lod);
				float it = 1.0f - t;

			// bezier
//				float b0 =     t * t  * t;
//				float b1 = 3 * t * t  * it;
//				float b2 = 3 * t * it * it;
//				float b3 =         it * it * it;

			// clumped bspline
				float b0 = it * it * it / 6.0f;
				float b1 = (3.0f * t * t * t - 6.0f * t * t + 4.0f) / 6.0f;
				float b2 = (-3.0f * t * t * t + 3.0f * t * t + 3.0f * t + 1.0f) / 6.0f;
				float b3 =  t * t * t / 6.0f;

				fvtx v0 = get_vtx(src, n + 0);
				fvtx v1 = get_vtx(src, n + 1);
				fvtx v2 = get_vtx(src, n + 2);
				fvtx v3 = get_vtx(src, n + 3);
				fvtx v;
				v.x = b0 * v0.x + b1 * v1.x + b2 * v2.x + b3 * v3.x;
				v.y = b0 * v0.y + b1 * v1.y + b2 * v2.y + b3 * v3.y;
				v.z = b0 * v0.z + b1 * v1.z + b2 * v2.z + b3 * v3.z;
				dst.push_back(v);
			}
		}

		return true;
	}
void asteroid_init(struct asteroid *a, double vel)
{
	get_vtx(a, LARGE_RAD);
	a->rad = LARGE_RAD;
	a->enable_draw_wrap = false;
	smp_obj_init((void*)a, 2);
	a->is_alive = true;
	phys_obj_init((void*)a, &phys_methods, NULL, 0);
	set_outside_spawn_pos_vel((void*)a, LARGE_RAD, vel);
	a->rotational_vel = drand() * MAX_ROTATIONAL_VEL;
	a->bnd = BND_GHOST;
	a->hb[0].rad = LARGE_RAD + MAX_VARIANCE * LARGE_RAD / 2.0;
	graphics_obj_init((void*)a, &draw_methods);
	a->type = OBJ_ENEMY;
	a->targetable = true;
}