📄 sphere.cpp
字号:
/* 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. *//** * sphere.cpp - Implementation for routines in the Sphere class * @author Brian Sweatt */#include <stdio.h>#include "sphere.h"#include "common.h"#ifndef __SPU__Sphere :: Sphere(const vector float &sphere, uint32_t materialID) : m_materialID(materialID) { m_x = vec_splat(sphere, 0); m_y = vec_splat(sphere, 1); m_z = vec_splat(sphere, 2); m_r = vec_splat(sphere, 3);}void Sphere::setPosition(vector float pos) { m_x = vec_splat(pos, 0); m_y = vec_splat(pos, 1); m_z = vec_splat(pos, 2);} void Sphere::translate(vector float dir) { m_x = vec_add(m_x, vec_splat(dir, 0)); m_y = vec_add(m_y, vec_splat(dir, 1)); m_z = vec_add(m_z, vec_splat(dir, 2));}#elseSphere::Sphere(const vector float &sphere, uint32_t materialID) :m_materialID(materialID){ vector unsigned char splat0 = (vector unsigned char) {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3}; vector unsigned char splat1 = (vector unsigned char) {4,5,6,7,4,5,6,7,4,5,6,7,4,5,6,7}; vector unsigned char splat2 = (vector unsigned char) {8,9,10,11,8,9,10,11,8,9,10,11,8,9,10,11}; vector unsigned char splat3 = (vector unsigned char) {12,13,14,15,12,13,14,15,12,13,14,15,12,13,14,15}; m_x = spu_shuffle(sphere, sphere, splat0); m_y = spu_shuffle(sphere, sphere, splat1); m_z = spu_shuffle(sphere, sphere, splat2); m_r = spu_shuffle(sphere, sphere, splat3);}void Sphere::setPosition(vector float pos) { vector unsigned char splat0 = (vector unsigned char) {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3}; vector unsigned char splat1 = (vector unsigned char) {4,5,6,7,4,5,6,7,4,5,6,7,4,5,6,7}; vector unsigned char splat2 = (vector unsigned char) {8,9,10,11,8,9,10,11,8,9,10,11,8,9,10,11}; vector unsigned char splat3 = (vector unsigned char) {12,13,14,15,12,13,14,15,12,13,14,15,12,13,14,15}; m_x = spu_shuffle(pos, pos, splat0); m_y = spu_shuffle(pos, pos, splat1); m_z = spu_shuffle(pos, pos, splat2);}void Sphere::translate(vector float dir) { vector unsigned char splat0 = (vector unsigned char) {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3}; vector unsigned char splat1 = (vector unsigned char) {4,5,6,7,4,5,6,7,4,5,6,7,4,5,6,7}; vector unsigned char splat2 = (vector unsigned char) {8,9,10,11,8,9,10,11,8,9,10,11,8,9,10,11}; vector unsigned char splat3 = (vector unsigned char) {12,13,14,15,12,13,14,15,12,13,14,15,12,13,14,15}; m_x = spu_add(m_x, spu_shuffle(dir, dir, splat0)); m_y = spu_add(m_y, spu_shuffle(dir, dir, splat1)); m_z = spu_add(m_z, spu_shuffle(dir, dir, splat2));}vector float Sphere::getBoundingBoxMin() { vector float center = (vector float) {spu_extract(m_x,0), \ spu_extract(m_y,0), \ spu_extract(m_z,0), \ 0.0f}; return spu_sub(center, m_r); }vector float Sphere::getBoundingBoxMax() { vector float center = (vector float) {spu_extract(m_x,0), \ spu_extract(m_y,0), \ spu_extract(m_z,0), \ 0.0f}; return spu_add(center, m_r); }#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -