⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 Ray tracing on PS3, using the acceleration of PPU, No SPE acceleration is used. The code must be com
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) 2007 Massachusetts Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *//**  * main.cpp - blue-steel Pong demo * @author Brian Sweatt *  * To be compiled and run on the PPU. This program runs a simple one-player version of pong. * Most of the code is for interfacing with the joystick (six-axis) and keyboard, as well as  * the simulation of the ball (very simple bouncing, no real physics). * Meant to show the ease of use of the blue-steel API. * (the rendering code takes up little more than 10 lines) * Enjoy! */extern "C" {#include <stdio.h>#include <stdlib.h>#include <libvector.h>#include <simdmath.h>#include <libspe.h>#include <libmisc.h>#include <unpack_rgba8_v.h>#include <math.h>#include </usr/include/linux/joystick.h>}#include "../src/sphere.h"#include "../src/common.h"#include "../src/rgbpacket.h"#include "../src/fb.h"#include "../src/objectset.h"#include "bsapi.h"//////////////////////////// Code from keyboard.h ////////////////////////////#define INITKEYBOARD ttycbreak()#define DEINITKEYBOARD ttynorm()/*   Keyboard support functions. January 7 1993 *//* obligatory includes. */#include <stdio.h>#include <sys/types.h>#include <ctype.h>#include <fcntl.h>#include <unistd.h>#include <termios.h>#include <sys/ioctl.h>                                  #ifndef FIONREAD#define FIONREAD TIOCINQ#endif#include <signal.h>static struct termios itio, tio;static int ttyfd  = -1;static int gottio = 0;/* Catch quit signals so we dont end up with a CBREAK terminal when   someone does a ^c during getch() */void sig1 (int sig){    tcsetattr (ttyfd, TCSANOW, &itio);    signal (sig, SIG_DFL);    kill (getpid(), sig);}/* initialize signals */void setsigs(){      signal (SIGINT,  sig1);    signal (SIGTSTP, sig1);    signal (SIGQUIT, sig1);}/* remove signals */void rmsigs(){    signal (SIGCONT, SIG_DFL);    signal (SIGINT,  SIG_DFL);    signal (SIGTSTP, SIG_DFL);    signal (SIGQUIT, SIG_DFL);}/* Put terminal in CBREAK mode */int ttycbreak(){    if (ttyfd == -1)	if ((ttyfd = open("/dev/tty", O_RDWR)) < 0)	    return 0;    if (tcgetattr(ttyfd, &tio) < 0)	return 0;    itio = tio;    setsigs();    gottio = 1;    tio.c_cc[VMIN] = 0;    tio.c_cc[VTIME] = 0;    tio.c_lflag &= ~(ECHO|ICANON);    tcsetattr (ttyfd, TCSANOW, &tio);    return 1;}/* Restore terminal */int ttynorm(){    gottio = 0;    tcsetattr (ttyfd, TCSANOW, &itio);    rmsigs();    return 1;}/* Unix kbhit() */int kbhit(){    long lf;    if (ioctl(ttyfd, FIONREAD, &lf) == -1)	return 0;    return lf;}/* Unix getch() */unsigned char getch(){    char c;    read(ttyfd, &c, 1);    return (unsigned char) c;}/////////////////////////// End keyboard.h code ///////////////////////////ObjectSet objects;vector unsigned int image[IMG_WIDTH*IMG_HEIGHT / 4] __attribute__((aligned(128)));int main(int argc, char** argv) {  dprintf("blue-steel parallel raytracer v0.1\r\n");  if(argc > 1) {    printf("%s", argv[1]);    int spes = atoi(argv[1]);    if(spes > 0 && spes <= TOTAL_SPES) {        NUM_RENDERING_SPES = spes;    }  }  INITKEYBOARD;    dprintf("Created spe threads\n");  uint32_t scene_size = (IMG_WIDTH * IMG_HEIGHT * sizeof(vector unsigned int));  ObjectSet *objects = (ObjectSet *) malloc_align(sizeof(ObjectSet), 7);    // One sphere for the ball... Not that we are setting the material to be refractive and bumpy  objects->num_spheres = 1;  objects->spheres = (Sphere *) malloc_align(sizeof(Sphere)*objects->num_spheres, 7);  objects->spheres[0] = Sphere((vector float) {0.5f, 0.5f, 0.041f, 0.04f}, 5);    // We're using 4 triangles... two for the ground, and two for the paddle  objects->num_triangles = 4;  objects->triangles = (Triangle *) malloc_align(sizeof(Triangle)*objects->num_spheres, 7);  objects->triangles[0] = Triangle((vector float) {0.0f, 0.0f, 0.0f, 0.0f}, 				   (vector float) {1.0f, 0.0f, 0.0f, 0.0f}, 				   (vector float) {1.0f, 1.0f, 0.0f, 0.0f},				   4);  objects->triangles[1] = Triangle((vector float) {0.0f, 0.0f, 0.0f, 0.0f},				   (vector float) {1.0f, 1.0f, 0.0f, 0.0f},				   (vector float) {0.0f, 1.0f, 0.0f, 0.0f},				   4);  objects->triangles[2] = Triangle((vector float) {0.4f, 0.02f, 0.01f, 0.0f}, 				   (vector float) {0.55f, 0.02f, 0.08f, 0.0f},				   (vector float) {0.4f, 0.02f, 0.08f, 0.0f},				   2);  objects->triangles[3] = Triangle((vector float) {0.4f, 0.02f, 0.01f, 0.0f},				   (vector float) {0.55f, 0.02f, 0.01f, 0.0f}, 				   (vector float) {0.55f, 0.02f, 0.08f, 0.0f}, 				   2);  // Defintions of the materials being used....  // Note that not all of these are used in this program, but are left as an example of how to   // create different types of materials  objects->num_materials = 9;  objects->materials = (material *) malloc_align(sizeof(material)*objects->num_materials, 7);    objects->materials[0].materialType = MATERIAL_PHONG;  objects->materials[0].diffuse_r = 0.0f;  objects->materials[0].diffuse_g = 0.0f;  objects->materials[0].diffuse_b = 0.0f;  objects->materials[0].arg1_i = 0;  objects->materials[0].arg1_f = 0.0f;  objects->materials[0].arg2_f = 0.0f;  objects->materials[0].specular_r = 0.0f;  objects->materials[0].specular_g = 0.0f;  objects->materials[0].specular_b = 0.0f;  objects->materials[0].reflective_r = 0.0f;  objects->materials[0].reflective_g = 0.0f;  objects->materials[0].reflective_b = 0.0f;  objects->materials[0].transparent_r = 0.0;  objects->materials[0].transparent_g = 0.0;  objects->materials[0].transparent_b = 0.0;    objects->materials[2].materialType = MATERIAL_PHONG;  objects->materials[2].diffuse_r = 0.0f;  objects->materials[2].diffuse_g = 0.5f;  objects->materials[2].diffuse_b = 0.7f;  objects->materials[2].arg1_i = 64;  objects->materials[2].specular_r = 1.0f;  objects->materials[2].specular_g = 1.0f;  objects->materials[2].specular_b = 1.0f;  objects->materials[2].reflective_r = 0.0f;  objects->materials[2].reflective_g = 0.5f;  objects->materials[2].reflective_b = 0.8f;  objects->materials[2].transparent_r = 0.0f;  objects->materials[2].transparent_g = 0.0f;  objects->materials[2].transparent_b = 0.0f;  objects->materials[3].materialType = MATERIAL_PHONG;  objects->materials[3].diffuse_r = 0.1f;  objects->materials[3].diffuse_g = 0.1f;  objects->materials[3].diffuse_b = 0.6f;  objects->materials[3].arg1_i = 128;  objects->materials[3].arg1_f = 1.05f;  objects->materials[3].specular_r = 1.0f;  objects->materials[3].specular_g = 1.0f;  objects->materials[3].specular_b = 1.0f;  objects->materials[3].reflective_r = 0.4f;  objects->materials[3].reflective_g = 0.4f;  objects->materials[3].reflective_b = 0.4f;  objects->materials[3].transparent_r = 0.9f;  objects->materials[3].transparent_g = 0.9f;  objects->materials[3].transparent_b = 0.9f;  objects->materials[4].materialType = MATERIAL_BUMP;  objects->materials[4].arg1_i = 1;  objects->materials[4].arg1_f = 0.4f;  objects->materials[4].arg2_f = 0.2f;  objects->materials[5].materialType = MATERIAL_BUMP;  objects->materials[5].arg1_i = 3;  objects->materials[5].arg1_f = 0.8f;  objects->materials[5].arg2_f = 0.3f;  objects->materials[1].materialType = MATERIAL_CHECKERBOARD;  objects->materials[1].colorDSRT_r = (vector float){10.f, 0.0f, 0.0f, 0.0f};  objects->materials[1].colorDSRT_g = (vector float){0.0f, 10.0f, 0.0f, 0.0f};  objects->materials[1].colorDSRT_b = (vector float){0.0f, 0.0f, 10.0f, 0.0f};  objects->materials[1].colorDSRT_a = (vector float){0.0f, 0.0f, 0.0f, 10.0f};  objects->materials[1].arg1_i = 7;  objects->materials[1].arg2_i = 8;     objects->materials[6].materialType = MATERIAL_WOOD;  objects->materials[6].colorDSRT_r = (vector float){10.0f, 0.0f, 0.0f, 0.0f};  objects->materials[6].colorDSRT_g = (vector float){0.0f, 100.0f, 0.0f, 0.0f};  objects->materials[6].colorDSRT_b = (vector float){0.0f, 0.0f, 100.0f, 0.0f};  objects->materials[6].colorDSRT_a = (vector float){0.0f, 0.0f, 0.0f, 50.0f};  objects->materials[6].arg1_f = 1.0f; //frequency  objects->materials[6].arg2_f = 5.0f; //amplitude  objects->materials[6].arg1_i = 7;  objects->materials[6].arg2_i = 8;    objects->materials[7].materialType = MATERIAL_PHONG;  objects->materials[7].diffuse_r = 0.0f;  objects->materials[7].diffuse_g = 0.0f;  objects->materials[7].diffuse_b = 0.0f;  objects->materials[7].arg1_i = 128;  objects->materials[7].arg1_f = 2.1f;  objects->materials[7].specular_r = 1.0f;  objects->materials[7].specular_g = 1.0f;  objects->materials[7].specular_b = 1.0f;  objects->materials[7].reflective_r = 0.8f;  objects->materials[7].reflective_g = 0.8f;  objects->materials[7].reflective_b = 0.8f;  objects->materials[7].transparent_r = 0.0f;  objects->materials[7].transparent_g = 0.0f;  objects->materials[7].transparent_b = 0.0f;  objects->materials[8].materialType = MATERIAL_PHONG;  objects->materials[8].diffuse_r = 0.8f;  objects->materials[8].diffuse_g = 0.8f;  objects->materials[8].diffuse_b = 0.8f;  objects->materials[8].arg1_i = 128;  objects->materials[8].arg1_f = 2.1f;  objects->materials[8].specular_r = 0.5f;  objects->materials[8].specular_g = 0.5f;  objects->materials[8].specular_b = 0.5f;  objects->materials[8].reflective_r = 0.0f;  objects->materials[8].reflective_g = 0.0f;  objects->materials[8].reflective_b = 0.0f;  objects->materials[8].transparent_r = 0.0f;  objects->materials[8].transparent_g = 0.0f;  objects->materials[8].transparent_b = 0.0f;    objects->num_lights = 1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -