// Copyright (C) 2011 Dave Griffiths // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "primitive.h" #include "../core/fixed.h" #include "../core/geometry.h" #include "../engine/scenenode.h" #ifdef _EE #include "ee/ps2-renderer.h" #endif #include "cube.h" primitive::primitive(unsigned int size, type t) { #ifndef _EE switch (t) { case TRIANGLES: m_type=GL_TRIANGLES; break; case TRISTRIP: m_type=GL_TRIANGLE_STRIP; break; default: m_type=GL_TRIANGLES; } #endif // store data contiguously m_size=size; } // (called in scenenode ctr) void primitive::build() { // todo: EE code: (vec3*)memalign(128, sizeof(vec3) * m_size vec3 *data = new vec3[m_size*4]; pdata_add("p",data); pdata_add("n",data+m_size); pdata_add("c",data+m_size*2); pdata_add("t",data+m_size*3); m_colours_=new u8[4*m_size]; m_positions=get_pdata_arr("p"); m_normals=get_pdata_arr("n"); m_colours=get_pdata_arr("c"); m_tex=get_pdata_arr("t"); } primitive::primitive() { m_size=12*3; #ifndef _EE m_type=GL_TRIANGLES; #endif vec3* data = new vec3[m_size*4]; pdata_add("p",data); pdata_add("n",data+m_size); pdata_add("c",data+m_size*2); pdata_add("t",data+m_size*3); m_colours_=new u8[4*m_size]; m_positions=get_pdata_arr("p"); m_normals=get_pdata_arr("n"); m_colours=get_pdata_arr("c"); m_tex=get_pdata_arr("t"); int p=0; for (int i=0; i(m_pdata.m_head); while (n!=NULL) { if (!strcmp(name,n->m_name)) { return n->m_array; } n=static_cast(n->m_next); } return NULL; } void primitive::pdata_set(const char* name, int i, vec3 v) { vec3* arr = get_pdata_arr(name); if (arr==NULL) return; arr[i]=v; } vec3 *primitive::pdata_get(const char* name, int i) { vec3* arr = get_pdata_arr(name); return &arr[i]; } void primitive::set_colour(flx_real r, flx_real g, flx_real b, flx_real a) { for (int i=0; im_positions[i]) m_bbmin=m_positions[i]; if (m_bbmax0) { points->add_to_front(interpolate_pdata(&m_pdata,t,bary,i1,i2,i3)); } } return points; } bool primitive::intersect_tristrip_fast(const vec3 &start, const vec3 &end) { vec3 bary; unsigned int i=2; while(i0.0) { return true; } } return false; } void primitive::render(u32 hints) { #ifdef _EE ps2_renderer::get()->render(0,m_size,&m_positions[0].x,&m_normals[0].x,&m_colours[0].x); #else #ifdef FLX_LINUX float *fltpos=new float[m_size*3]; float *fltnrm=new float[m_size*3]; float *fltcol=new float[m_size*3]; float *flttex=new float[m_size*3]; int pos=0; int cpos=0; for (int i=0; i