Esempio n. 1
0
void updateCamera(Scene* scene) {
	double time = WallClockTime() - sceneTimeOffset;
	double rtime = (time / 21.35634); // camera rotation time
	rtime = rtime - floor(rtime);

	double btime = (time / 59.8752); // camera bobbing time
	btime = btime - floor(btime);

	double ltime = (time / 98.7654); // light rotation time
	ltime = ltime - floor(ltime);

	double lbtime = (time / 92.764); // light bobbing time
	lbtime = lbtime - floor(lbtime);

	camInit(scene->cam);
	cl_float3 pos;
	cl_float3 center;
	vecInit(center, 14.9f, 9.7f, -14.85f);
	vecInit(pos, 33.0f * sin(rtime * M_PI * 2.0),
			8.0f * sin(btime * M_PI * 2.0 + 0.3),
			33.0f * (cos(rtime * M_PI * 2.0) - 0.11));
	vecAdd(pos, center);
	camMove(scene->cam, pos);
	camLookAt(scene->cam, center);

	vecInit(pos, 5.0f * sin(-ltime * M_PI * 2.0),
			8.0f + 6.0f * sin(lbtime * M_PI * 2.0),
			5.0f * cos(ltime * M_PI * 2.0));
	vecNormalize(pos);
	scene->lightDir = pos;
}
Esempio n. 2
0
void processMouseActiveMotion(int x, int y)
{
//    printf("processMouseActiveMotion\n");
    camMove( cam, x, y);
}
Esempio n. 3
0
	virtual void KeyCallBack(unsigned char key, int x, int y) {
		bool needRedisplay = true;

		switch (key) {
			case 'p': {
				// Write image to PPM file
				std::ofstream f("image.ppm", std::ofstream::trunc);
				if (!f.good()) {
					OCLTOY_LOG("Failed to open image file: image.ppm");
				} else {
					f << "P3" << std::endl;
					f << windowWidth << " " << windowHeight << std::endl;
					f << "255" << std::endl;

					for (int y = windowHeight - 1; y >= 0; --y) {
						const PixelRGBA8888 *p = &bitmap->pixels[y * windowWidth];
						for (int x = 0; x < windowWidth; ++x, p++) {
							const std::string r = boost::lexical_cast<std::string>((unsigned int)p->r);
							const std::string g = boost::lexical_cast<std::string>((unsigned int)p->g);
							const std::string b = boost::lexical_cast<std::string>((unsigned int)p->b);
							f << r << " " << g << " " << b << std::endl;
						}
					}
				}
				f.close();
				OCLTOY_LOG("Saved framebuffer in image.ppm");

				needRedisplay = false;
				break;
			}
			case 27: // Escape key
			case 'q':
			case 'Q':
				OCLTOY_LOG("Done");

				exit(EXIT_SUCCESS);
				break;
			case ' ': // Restart rendering
				animCamera = true;
				sceneTimeOffset = WallClockTime();
				setupAnim(scene, windowWidth, windowHeight);
				break;
			case 'h':
				printHelp = (!printHelp);
				break;
			case 'a': {
				animCamera = false;
				cl_float3 dir = scene->cam.viewRight;
				vecNormalize(dir);
				vecScale(dir, -MOVE_STEP);
				camMove(scene->cam, dir);
				break;
			}
			case 'd': {
				animCamera = false;
				cl_float3 dir = scene->cam.viewRight;
				vecNormalize(dir);
				vecScale(dir, MOVE_STEP);
				camMove(scene->cam, dir);
				break;
			}
			case 'w': {
				animCamera = false;
				cl_float3 dir = scene->cam.viewCenter;
				vecSub(dir, scene->cam.eye);
				vecNormalize(dir);
				vecScale(dir, MOVE_STEP);
				camMove(scene->cam, dir);
				break;
			}
			case 's': {
				animCamera = false;
				cl_float3 dir = scene->cam.viewCenter;
				vecSub(dir, scene->cam.eye);
				vecNormalize(dir);
				vecScale(dir, -MOVE_STEP);
				camMove(scene->cam, dir);
				break;
			}
			case 'r': {
				animCamera = false;
				cl_float3 dir;
				vecInit(dir, 0.f, MOVE_STEP, 0.f);
				camMove(scene->cam, dir);
				break;
			}
			case 'f': {
				animCamera = false;
				cl_float3 dir;
				vecInit(dir, 0.f, -MOVE_STEP, 0.f);
				camMove(scene->cam, dir);
				break;
			}
			default:
				needRedisplay = false;
				break;
		}

		if (needRedisplay)
			glutPostRedisplay();
	}
Esempio n. 4
0
void setupAnim(Scene* scene, int imgWidth, int imgHeight) {

	// Positions Everybody!
	scene->numSpheres = NUMSPHERES;

	// three mirrored juggling spheres
	for (int i = 0; i <= 2; i++) {
		scene->spheres[i].radius = 1.4f;
		vecInit(scene->spheres[i].color, 0.5f, 0.5f, 0.5f);
		scene->spheres[i].ambient = 0.1f;
		scene->spheres[i].diffuse = 0.3f;
		scene->spheres[i].highlight = 0.8f;
		scene->spheres[i].roughness = 0.05f;
		scene->spheres[i].reflection = 0.8f;
	}
	vecInit(scene->spheres[0].center, 11.0f, 0.0f, 0.0f);
	vecInit(scene->spheres[1].center, 11.0f, 0.0f, 0.0f);
	vecInit(scene->spheres[2].center, 11.0f, 0.0f, 0.0f);

	// torso: seven spheres
	for (int i = 3; i <= 10; i++) {
		float fraction = float(i - 3) / 7.0f;
		scene->spheres[i].radius = 1.6f + 0.4f * fraction;
		vecInit(scene->spheres[i].center, 15.1f, 8.5f + 3.2f * fraction, -15.1f);
		vecInit(scene->spheres[i].color, 0.843f, 0.12f, 0.11f);
		scene->spheres[i].ambient = 0.3f;
		scene->spheres[i].diffuse = 0.8f;
		scene->spheres[i].highlight = 1.0f;
		scene->spheres[i].roughness = 0.1f;
		scene->spheres[i].reflection = 0.0f;
	}

	// head
	scene->spheres[11].radius = 1.4;
	vecInit(scene->spheres[11].center, 15.1f, 15.5f, -15.1f);
	vecInit(scene->spheres[11].color, 0.95f, 0.64f, 0.63f);
	scene->spheres[11].ambient = 0.25f;
	scene->spheres[11].diffuse = 0.9f;
	scene->spheres[11].highlight = 1.0f;
	scene->spheres[11].roughness = 0.1f;
	scene->spheres[11].reflection = 0.0f;

	// neck
	scene->spheres[12].radius = 0.5;
	vecInit(scene->spheres[12].center, 15.1f, 14.0f, -15.1f);
	vecInit(scene->spheres[12].color, 0.95f, 0.64f, 0.63f);
	scene->spheres[12].ambient = 0.25f;
	scene->spheres[12].diffuse = 0.9f;
	scene->spheres[12].highlight = 1.0f;
	scene->spheres[12].roughness = 0.1f;
	scene->spheres[12].reflection = 0.0f;

	// outer limb parts
	for (int i = 13; i <= 20; i++) {
		for (int j = 0; j < 4; j++) {
			scene->spheres[i + 17 * j].radius = 0.25f + 0.25f * float(i - 13) / 7.0f;
			vecInit(scene->spheres[i + 17 * j].center, 0.0f, 0.0f, 0.0f);
			vecInit(scene->spheres[i + 17 * j].color, 0.95f, 0.64f, 0.63f);
			scene->spheres[i + 17 * j].ambient = 0.25f;
			scene->spheres[i + 17 * j].diffuse = 0.9f;
			scene->spheres[i + 17 * j].highlight = 1.0f;
			scene->spheres[i + 17 * j].roughness = 0.1f;
			scene->spheres[i + 17 * j].reflection = 0.0f;
		}
	}

	// inner limb parts
	for (int i = 21; i <= 29; i++) {
		for (int j = 0; j < 4; j++) {
			scene->spheres[i + 17 * j].radius = 0.5f;
			vecInit(scene->spheres[i + 17 * j].center, 0.0f, 0.0f, 0.0f);
			vecInit(scene->spheres[i + 17 * j].color, 0.95f, 0.64f, 0.63f);
			scene->spheres[i + 17 * j].ambient = 0.25f;
			scene->spheres[i + 17 * j].diffuse = 0.9f;
			scene->spheres[i + 17 * j].highlight = 1.0f;
			scene->spheres[i + 17 * j].roughness = 0.1f;
			scene->spheres[i + 17 * j].reflection = 0.0f;
		}
	}

	// eyes
	scene->spheres[81].radius = 0.4;
	vecInit(scene->spheres[81].center, 14.2f, 15.4f, -14.4f);
	vecInit(scene->spheres[81].color, 0.121f, 0.105f, 0.58f);
	scene->spheres[81].ambient = 0.25f;
	scene->spheres[81].diffuse = 0.9f;
	scene->spheres[81].highlight = 1.0f;
	scene->spheres[81].roughness = 0.1f;
	scene->spheres[81].reflection = 0.0f;

	scene->spheres[82].radius = 0.4;
	vecInit(scene->spheres[82].center, 14.2f, 15.4f, -14.4f);
	vecInit(scene->spheres[82].color, 0.121f, 0.105f, 0.58f);
	scene->spheres[82].ambient = 0.25f;
	scene->spheres[82].diffuse = 0.9f;
	scene->spheres[82].highlight = 1.0f;
	scene->spheres[82].roughness = 0.1f;
	scene->spheres[82].reflection = 0.0f;

	// hair
	scene->spheres[83].radius = 1.4;
	vecInit(scene->spheres[83].center, 15.2f, 15.4f, -15.1f);
	vecInit(scene->spheres[83].color, 0.15f, 0.066f, 0.09f);
	scene->spheres[83].ambient = 0.25f;
	scene->spheres[83].diffuse = 0.9f;
	scene->spheres[83].highlight = 1.0f;
	scene->spheres[83].roughness = 0.1f;
	scene->spheres[83].reflection = 0.0f;

	// Lights!
	vecInit(scene->lightDir, -56.4f, 68.6f, 34.7f);
	vecNormalize(scene->lightDir);

	// Camera!
	camInit(scene->cam);
	cl_float3 tmp;
	vecInit(tmp, -7.8f, 10.0f, 7.8f);
	camMove(scene->cam, tmp);
	vecInit(tmp, 80.0f, 10.7f, -100.0f);
	camLookAt(scene->cam, tmp);
	scene->cam.imgWidth = imgWidth;
	scene->cam.imgHeight = imgHeight;

	// Action!
	animatePositions(scene, true);
}