📄 triangle.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. *//** * triangle.cpp - Implementation for the routines in the triangle class * @author Brian Sweatt */extern "C" {#include <rotate_matrix4x4.h>#include <xform_vec3.h>#include <stdio.h>#include <libmisc.h>}#include "triangle.h"#include "common.h"#include <load_vec_float4.h>#define load_vec_float4 _load_vec_float4#ifndef __SPU__Triangle::Triangle(const vector float &a, const vector float &b, const vector float &c, const uint32_t &m): m_materialID(m) { m_a = a; m_ab = vec_sub(b, a); m_ac = vec_sub(c, a); m_n = _normalize3(_cross_product3(m_ab, m_ac));} void Triangle::translate(vector float dir) { m_a = vec_add(m_a, dir);}/** * Rotates all the points of this triangle by rad radians around the point px, py, pz * Rather than transforming the normal, it is faster to simply recompute the normal * using cross products... This works for flat shading with one normal only. * For smooth shading the normals at each vertex will need to be transformed by the * inverse transpose matrix. */void Triangle::rotate(float rad, const vector float ¢er, const vector float &axis) { vector float mat[4]; vector float invt[4]; vector float w = (vector float) {0.0f, 0.0f, 0.0f, 1.0f}; vector float m_b = vec_add(m_a, m_ab); vector float m_c = vec_add(m_a, m_ac); vector float refa = vec_add(vec_sub(m_a, center), w); vector float refb = vec_add(vec_sub(m_b, center), w); vector float refc = vec_add(vec_sub(m_c, center), w); _rotate_matrix4x4(mat, axis, rad); refa = _xform_vec3(refa, mat); refb = _xform_vec3(refb, mat); refc = _xform_vec3(refc, mat); m_a = vec_add(refa, center); refb = vec_add(refb, center); refc = vec_add(refc, center); m_ab = vec_sub(refb, m_a); m_ac = vec_sub(refc, m_a); m_n = _normalize3(_cross_product3(m_ab, m_ac)); return;}#elseTriangle::Triangle(const vector float &a, const vector float &b, const vector float &c, const uint32_t &m) :m_materialID(m){ m_a = a; m_ab = spu_sub(b, a); m_ac = spu_sub(c, a); m_n = _normalize3(_cross_product3(m_ab, m_ac));}void Triangle::translate(vector float dir) { m_a = spu_add(m_a, dir);}vector float Triangle::getBoundingBoxMin() { vector float b = spu_add(m_a, m_ab); vector float c = spu_add(m_a, m_ac); return _fminf4(m_a,_fminf4(b,c)); }vector float Triangle::getBoundingBoxMax() { vector float b = spu_add(m_a, m_ab); vector float c = spu_add(m_a, m_ac); return _fmaxf4(m_a,_fmaxf4(b,c)); } #endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -