Exemple #1
0
void Terrain::SetPositionLight(float x, float y, float z)
{
	SetPositionLight(Vector3f(x, y, z));
}
Exemple #2
0
static int populate_lights(Vector *lights) {

	size_t i;
	size_t n;
	int s;
	hash *light_h;
	char *name, *type, *aux;
	Vector *v;
	set *S;

	float r, g, b, w;
	float rgb[3], pos4[4];
	float cutoff = 30.0;
	float exp = 10.0;

	Light *l;

	if (!lights) return -1;
	n  = sizeVector(lights);
	for(i = 0; i < n; i++) {
		S = CreateSet();
		light_h = (hash *) atVector(lights, i);
		name = (char *) FindHashElement(light_h, "name");
		type = (char *) FindHashElement(light_h, "type");
		if (!check_light_type(type)) {
			fprintf(stderr, "[E] populate_lights: bad light type %s (possible values \"positional\", \"directional\", \"spotlight\")\n", type);
			exit(1);
		}

		if (!name) return i;
		if (!type) return i;
		InsertSetElement(S, "name");
		InsertSetElement(S, "type");
		l = SceneRegisterLight(name);
		v = (Vector *) FindHashElement(light_h, "pos");
		if (v) {
			InsertSetElement(S, "pos");
			read_xyz(v, &pos4[0], &pos4[1], &pos4[2]);
			pos4[3] = 1.0;
			if (!strcmp(type, "directional")) pos4[3] = 0.0;
			SetPositionLight(l, &pos4[0]);
		}

		v = (Vector *) FindHashElement(light_h, "amb");
		if (v) {
			InsertSetElement(S, "amb");
			read_xyz(v, &rgb[0], &rgb[1], &rgb[2]);
			SetAmbientLight(l, &rgb[0]);
		}

		v = (Vector *) FindHashElement(light_h, "dif");
		if (v) {
			InsertSetElement(S, "dif");
			read_xyz(v, &rgb[0], &rgb[1], &rgb[2]);
			SetDiffuseLight(l, &rgb[0]);
		}

		v = (Vector *) FindHashElement(light_h, "spec");
		if (v) {
			InsertSetElement(S, "spec");
			read_xyz(v, &rgb[0], &rgb[1], &rgb[2]);
			SetSpecularLight(l, &rgb[0]);
		}

		if (!strcmp(type, "spotlight")) {
			aux = (char *) FindHashElement(light_h, "exp");
			if (aux) {
				InsertSetElement(S, "exp");
				sscanf(aux, "%f", &exp);
				if (exp < 0) {
					fprintf(stderr, "[E] populate_lights: negative exponent\n");
					exit(1);
				}
				free(aux);
			}
			aux = (char *) FindHashElement(light_h, "cutoff");
			if (aux) {
				InsertSetElement(S, "cutoff");
				sscanf(aux, "%f", &cutoff);
				if (exp < 0) {
					fprintf(stderr, "[E] populate_lights: negative cutoff\n");
					exit(1);
				}
				free(aux);
			}
			rgb[0] = 0.577; rgb[1] = 0.577; rgb[2] = 0.577;
			v = (Vector *) FindHashElement(light_h, "spdir");
			if (v) {
				InsertSetElement(S, "spdir");
				read_xyz(v, &rgb[0], &rgb[1], &rgb[2]);
			}
			SetSpotLight(l, &rgb[0], cutoff, exp);
		}
		aux = (char *) FindHashElement(light_h, "switched");
		if (aux) {
			InsertSetElement(S, "switched");
			sscanf(aux, "%d", &s);
			if (!s) SwitchLight(l, 0);
			free(aux);
		}
		free(type);
		free(name);
		check_and_destroy("populate_lights", light_h, S);
		//DestroyHash(&light_h);
	}
	DestroyVector(&lights);
	return -1;
}