nuclear@1: #include nuclear@1: #include nuclear@1: #include nuclear@1: #include nuclear@1: #include "opengl.h" nuclear@1: #include "mesh.h" nuclear@1: #include "xform_node.h" nuclear@1: //#include "logger.h" nuclear@1: nuclear@1: int Mesh::global_sdr_loc[NUM_MESH_ATTR] = { 0, 1, 2, 3, 4, 5 }; nuclear@1: unsigned int Mesh::intersect_mode = ISECT_DEFAULT; nuclear@1: float Mesh::vertex_sel_dist = 0.01; nuclear@1: float Mesh::vis_vecsize = 1.0; nuclear@1: nuclear@1: Mesh::Mesh() nuclear@1: { nuclear@1: clear(); nuclear@1: nuclear@1: glGenBuffers(NUM_MESH_ATTR + 1, buffer_objects); nuclear@1: nuclear@1: for(int i=0; iname = name; nuclear@1: } nuclear@1: nuclear@1: const char *Mesh::get_name() const nuclear@1: { nuclear@1: return name.c_str(); nuclear@1: } nuclear@1: nuclear@1: bool Mesh::has_attrib(int attr) const nuclear@1: { nuclear@1: if(attr < 0 || attr >= NUM_MESH_ATTR) { nuclear@1: return false; nuclear@1: } nuclear@1: nuclear@1: // if neither of these is valid, then nobody has set this attribute nuclear@1: return vattr[attr].vbo_valid || vattr[attr].data_valid; nuclear@1: } nuclear@1: nuclear@1: void Mesh::clear() nuclear@1: { nuclear@1: bones.clear(); nuclear@1: nuclear@1: for(int i=0; i= NUM_MESH_ATTR) { nuclear@1: fprintf(stderr, "%s: invalid attrib: %d\n", __FUNCTION__, attrib); nuclear@1: return 0; nuclear@1: } nuclear@1: nuclear@1: if(nverts && num != nverts) { nuclear@1: fprintf(stderr, "%s: attribute count missmatch (%d instead of %d)\n", __FUNCTION__, num, nverts); nuclear@1: return 0; nuclear@1: } nuclear@1: nverts = num; nuclear@1: nuclear@1: vattr[attrib].data.clear(); nuclear@1: vattr[attrib].nelem = nelem; nuclear@1: vattr[attrib].data.resize(num * nelem); nuclear@1: nuclear@1: if(data) { nuclear@1: memcpy(&vattr[attrib].data[0], data, num * nelem * sizeof *data); nuclear@1: } nuclear@1: nuclear@1: vattr[attrib].data_valid = true; nuclear@1: vattr[attrib].vbo_valid = false; nuclear@1: return &vattr[attrib].data[0]; nuclear@1: } nuclear@1: nuclear@1: float *Mesh::get_attrib_data(int attrib) nuclear@1: { nuclear@1: if(attrib < 0 || attrib >= NUM_MESH_ATTR) { nuclear@1: fprintf(stderr, "%s: invalid attrib: %d\n", __FUNCTION__, attrib); nuclear@1: return 0; nuclear@1: } nuclear@1: nuclear@1: vattr[attrib].vbo_valid = false; nuclear@1: return (float*)((const Mesh*)this)->get_attrib_data(attrib); nuclear@1: } nuclear@1: nuclear@1: const float *Mesh::get_attrib_data(int attrib) const nuclear@1: { nuclear@1: if(attrib < 0 || attrib >= NUM_MESH_ATTR) { nuclear@1: fprintf(stderr, "%s: invalid attrib: %d\n", __FUNCTION__, attrib); nuclear@1: return 0; nuclear@1: } nuclear@1: nuclear@1: if(!vattr[attrib].data_valid) { nuclear@1: #if GL_ES_VERSION_2_0 nuclear@1: fprintf(stderr, "%s: can't read back attrib data on CrippledGL ES\n", __FUNCTION__); nuclear@1: return 0; nuclear@1: #else nuclear@1: if(!vattr[attrib].vbo_valid) { nuclear@1: fprintf(stderr, "%s: unavailable attrib: %d\n", __FUNCTION__, attrib); nuclear@1: return 0; nuclear@1: } nuclear@1: nuclear@1: // local data copy is unavailable, grab the data from the vbo nuclear@1: Mesh *m = (Mesh*)this; nuclear@1: m->vattr[attrib].data.resize(nverts * vattr[attrib].nelem); nuclear@1: nuclear@1: glBindBuffer(GL_ARRAY_BUFFER, vattr[attrib].vbo); nuclear@1: void *data = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY); nuclear@1: memcpy(&m->vattr[attrib].data[0], data, nverts * vattr[attrib].nelem * sizeof(float)); nuclear@1: glUnmapBuffer(GL_ARRAY_BUFFER); nuclear@1: nuclear@1: vattr[attrib].data_valid = true; nuclear@1: #endif nuclear@1: } nuclear@1: nuclear@1: return &vattr[attrib].data[0]; nuclear@1: } nuclear@1: nuclear@1: void Mesh::set_attrib(int attrib, int idx, const Vector4 &v) nuclear@1: { nuclear@1: float *data = get_attrib_data(attrib); nuclear@1: if(data) { nuclear@1: data += idx * vattr[attrib].nelem; nuclear@1: for(int i=0; iget_index_data(); nuclear@1: } nuclear@1: nuclear@1: const unsigned int *Mesh::get_index_data() const nuclear@1: { nuclear@1: if(!idata_valid) { nuclear@1: #if GL_ES_VERSION_2_0 nuclear@1: fprintf(stderr, "%s: can't read back index data in CrippledGL ES\n", __FUNCTION__); nuclear@1: return 0; nuclear@1: #else nuclear@1: if(!ibo_valid) { nuclear@1: fprintf(stderr, "%s: indices unavailable\n", __FUNCTION__); nuclear@1: return 0; nuclear@1: } nuclear@1: nuclear@1: // local data copy is unavailable, gram the data from the ibo nuclear@1: Mesh *m = (Mesh*)this; nuclear@1: int nidx = nfaces * 3; nuclear@1: m->idata.resize(nidx); nuclear@1: nuclear@1: glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); nuclear@1: void *data = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_READ_ONLY); nuclear@1: memcpy(&m->idata[0], data, nidx * sizeof(unsigned int)); nuclear@1: glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); nuclear@1: nuclear@1: idata_valid = true; nuclear@1: #endif nuclear@1: } nuclear@1: nuclear@1: return &idata[0]; nuclear@1: } nuclear@1: nuclear@1: void Mesh::append(const Mesh &mesh) nuclear@1: { nuclear@1: unsigned int idxoffs = nverts; nuclear@1: nuclear@1: nverts += mesh.nverts; nuclear@1: nfaces += mesh.nfaces; nuclear@1: nuclear@1: for(int i=0; i= NUM_MESH_ATTR) { nuclear@1: return; nuclear@1: } nuclear@1: Mesh::global_sdr_loc[attr] = loc; nuclear@1: } nuclear@1: nuclear@1: /// static function nuclear@1: int Mesh::get_attrib_location(int attr) nuclear@1: { nuclear@1: if(attr < 0 || attr >= NUM_MESH_ATTR) { nuclear@1: return -1; nuclear@1: } nuclear@1: return Mesh::global_sdr_loc[attr]; nuclear@1: } nuclear@1: nuclear@1: /// static function nuclear@1: void Mesh::clear_attrib_locations() nuclear@1: { nuclear@1: for(int i=0; i= (int)bones.size()) { nuclear@1: return 0; nuclear@1: } nuclear@1: return bones[idx]; nuclear@1: } nuclear@1: nuclear@1: int Mesh::get_bones_count() const nuclear@1: { nuclear@1: return (int)bones.size(); nuclear@1: } nuclear@1: nuclear@1: void Mesh::draw() const nuclear@1: { nuclear@1: ((Mesh*)this)->update_buffers(); nuclear@1: nuclear@1: if(!vattr[MESH_ATTR_VERTEX].vbo_valid) { nuclear@1: fprintf(stderr, "%s: invalid vertex buffer\n", __FUNCTION__); nuclear@1: return; nuclear@1: } nuclear@1: if(global_sdr_loc[MESH_ATTR_VERTEX] == -1) { nuclear@1: fprintf(stderr, "%s: shader attribute location for vertices unset\n", __FUNCTION__); nuclear@1: return; nuclear@1: } nuclear@1: nuclear@1: for(int i=0; i= 0 && vattr[i].vbo_valid) { nuclear@1: glBindBuffer(GL_ARRAY_BUFFER, vattr[i].vbo); nuclear@1: glVertexAttribPointer(loc, vattr[i].nelem, GL_FLOAT, GL_FALSE, 0, 0); nuclear@1: glEnableVertexAttribArray(loc); nuclear@1: } nuclear@1: } nuclear@1: glBindBuffer(GL_ARRAY_BUFFER, 0); nuclear@1: nuclear@1: if(ibo_valid) { nuclear@1: glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); nuclear@1: glDrawElements(GL_TRIANGLES, nfaces * 3, GL_UNSIGNED_INT, 0); nuclear@1: glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); nuclear@1: } else { nuclear@1: glDrawArrays(GL_TRIANGLES, 0, nverts); nuclear@1: } nuclear@1: nuclear@1: for(int i=0; i= 0 && vattr[i].vbo_valid) { nuclear@1: glDisableVertexAttribArray(loc); nuclear@1: } nuclear@1: } nuclear@1: } nuclear@1: nuclear@1: void Mesh::draw_wire() const nuclear@1: { nuclear@1: ((Mesh*)this)->update_wire_ibo(); nuclear@1: nuclear@1: if(!vattr[MESH_ATTR_VERTEX].vbo_valid || !wire_ibo_valid) { nuclear@1: fprintf(stderr, "%s: invalid vertex buffer\n", __FUNCTION__); nuclear@1: return; nuclear@1: } nuclear@1: if(global_sdr_loc[MESH_ATTR_VERTEX] == -1) { nuclear@1: fprintf(stderr, "%s: shader attribute location for vertices unset\n", __FUNCTION__); nuclear@1: return; nuclear@1: } nuclear@1: nuclear@1: for(int i=0; i= 0 && vattr[i].vbo_valid) { nuclear@1: glBindBuffer(GL_ARRAY_BUFFER, vattr[i].vbo); nuclear@1: glVertexAttribPointer(loc, vattr[i].nelem, GL_FLOAT, GL_FALSE, 0, 0); nuclear@1: glEnableVertexAttribArray(loc); nuclear@1: } nuclear@1: } nuclear@1: glBindBuffer(GL_ARRAY_BUFFER, 0); nuclear@1: nuclear@1: glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, wire_ibo); nuclear@1: glDrawElements(GL_LINES, nfaces * 6, GL_UNSIGNED_INT, 0); nuclear@1: glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); nuclear@1: nuclear@1: for(int i=0; i= 0 && vattr[i].vbo_valid) { nuclear@1: glDisableVertexAttribArray(loc); nuclear@1: } nuclear@1: } nuclear@1: } nuclear@1: nuclear@1: void Mesh::draw_vertices() const nuclear@1: { nuclear@1: ((Mesh*)this)->update_buffers(); nuclear@1: nuclear@1: if(!vattr[MESH_ATTR_VERTEX].vbo_valid) { nuclear@1: fprintf(stderr, "%s: invalid vertex buffer\n", __FUNCTION__); nuclear@1: return; nuclear@1: } nuclear@1: if(global_sdr_loc[MESH_ATTR_VERTEX] == -1) { nuclear@1: fprintf(stderr, "%s: shader attribute location for vertices unset\n", __FUNCTION__); nuclear@1: return; nuclear@1: } nuclear@1: nuclear@1: for(int i=0; i= 0 && vattr[i].vbo_valid) { nuclear@1: glBindBuffer(GL_ARRAY_BUFFER, vattr[i].vbo); nuclear@1: glVertexAttribPointer(loc, vattr[i].nelem, GL_FLOAT, GL_FALSE, 0, 0); nuclear@1: glEnableVertexAttribArray(loc); nuclear@1: } nuclear@1: } nuclear@1: glBindBuffer(GL_ARRAY_BUFFER, 0); nuclear@1: nuclear@1: glDrawArrays(GL_POINTS, 0, nverts); nuclear@1: nuclear@1: for(int i=0; i= 0 && vattr[i].vbo_valid) { nuclear@1: glDisableVertexAttribArray(loc); nuclear@1: } nuclear@1: } nuclear@1: } nuclear@1: nuclear@1: void Mesh::draw_normals() const nuclear@1: { nuclear@1: #ifdef USE_OLDGL nuclear@1: int vert_loc = global_sdr_loc[MESH_ATTR_VERTEX]; nuclear@1: Vector3 *varr = (Vector3*)get_attrib_data(MESH_ATTR_VERTEX); nuclear@1: Vector3 *norm = (Vector3*)get_attrib_data(MESH_ATTR_NORMAL); nuclear@1: nuclear@1: if(!varr || !norm || vert_loc < 0) { nuclear@1: return; nuclear@1: } nuclear@1: nuclear@1: glBegin(GL_LINES); nuclear@1: for(size_t i=0; icalc_aabb(); nuclear@1: } nuclear@1: *vmin = aabb.min; nuclear@1: *vmax = aabb.max; nuclear@1: } nuclear@1: nuclear@1: const AABox &Mesh::get_aabbox() const nuclear@1: { nuclear@1: if(!aabb_valid) { nuclear@1: ((Mesh*)this)->calc_aabb(); nuclear@1: } nuclear@1: return aabb; nuclear@1: } nuclear@1: nuclear@1: float Mesh::get_bsphere(Vector3 *center, float *rad) const nuclear@1: { nuclear@1: if(!bsph_valid) { nuclear@1: ((Mesh*)this)->calc_bsph(); nuclear@1: } nuclear@1: *center = bsph.center; nuclear@1: *rad = bsph.radius; nuclear@1: return bsph.radius; nuclear@1: } nuclear@1: nuclear@1: const Sphere &Mesh::get_bsphere() const nuclear@1: { nuclear@1: if(!bsph_valid) { nuclear@1: ((Mesh*)this)->calc_bsph(); nuclear@1: } nuclear@1: return bsph; nuclear@1: } nuclear@1: nuclear@1: /// static function nuclear@1: void Mesh::set_intersect_mode(unsigned int mode) nuclear@1: { nuclear@1: Mesh::intersect_mode = mode; nuclear@1: } nuclear@1: nuclear@1: /// static function nuclear@1: unsigned int Mesh::get_intersect_mode() nuclear@1: { nuclear@1: return Mesh::intersect_mode; nuclear@1: } nuclear@1: nuclear@1: /// static function nuclear@1: void Mesh::set_vertex_select_distance(float dist) nuclear@1: { nuclear@1: Mesh::vertex_sel_dist = dist; nuclear@1: } nuclear@1: nuclear@1: /// static function nuclear@1: float Mesh::get_vertex_select_distance() nuclear@1: { nuclear@1: return Mesh::vertex_sel_dist; nuclear@1: } nuclear@1: nuclear@1: /*bool Mesh::intersect(const Ray &ray, HitPoint *hit) const nuclear@1: { nuclear@1: assert((Mesh::intersect_mode & (ISECT_VERTICES | ISECT_FACE)) != (ISECT_VERTICES | ISECT_FACE)); nuclear@1: nuclear@1: const Vector3 *varr = (Vector3*)get_attrib_data(MESH_ATTR_VERTEX); nuclear@1: const Vector3 *narr = (Vector3*)get_attrib_data(MESH_ATTR_NORMAL); nuclear@1: if(!varr) { nuclear@1: return false; nuclear@1: } nuclear@1: const unsigned int *idxarr = get_index_data(); nuclear@1: nuclear@1: // first test with the bounding box nuclear@1: AABox box; nuclear@1: get_aabbox(&box.min, &box.max); nuclear@1: if(!box.intersect(ray)) { nuclear@1: return false; nuclear@1: } nuclear@1: nuclear@1: HitPoint nearest_hit; nuclear@1: nearest_hit.dist = FLT_MAX; nuclear@1: nearest_hit.obj = 0; nuclear@1: nuclear@1: if(Mesh::intersect_mode & ISECT_VERTICES) { nuclear@1: // we asked for "intersections" with the vertices of the mesh nuclear@1: long nearest_vidx = -1; nuclear@1: float thres_sq = Mesh::vertex_sel_dist * Mesh::vertex_sel_dist; nuclear@1: nuclear@1: for(unsigned int i=0; i 0) { nuclear@1: continue; nuclear@1: } nuclear@1: nuclear@1: // project the vertex onto the ray line nuclear@1: float t = dot_product(varr[i] - ray.origin, ray.dir); nuclear@1: Vector3 vproj = ray.origin + ray.dir * t; nuclear@1: nuclear@1: float dist_sq = (vproj - varr[i]).length_sq(); nuclear@1: if(dist_sq < thres_sq) { nuclear@1: if(!hit) { nuclear@1: return true; nuclear@1: } nuclear@1: if(t < nearest_hit.dist) { nuclear@1: nearest_hit.dist = t; nuclear@1: nearest_vidx = i; nuclear@1: } nuclear@1: } nuclear@1: } nuclear@1: nuclear@1: if(nearest_vidx != -1) { nuclear@1: hitvert = varr[nearest_vidx]; nuclear@1: nearest_hit.obj = &hitvert; nuclear@1: } nuclear@1: nuclear@1: } else { nuclear@1: // regular intersection test with polygons nuclear@1: nuclear@1: for(unsigned int i=0; i 0) { nuclear@1: continue; nuclear@1: } nuclear@1: nuclear@1: HitPoint fhit; nuclear@1: if(face.intersect(ray, hit ? &fhit : 0)) { nuclear@1: if(!hit) { nuclear@1: return true; nuclear@1: } nuclear@1: if(fhit.dist < nearest_hit.dist) { nuclear@1: nearest_hit = fhit; nuclear@1: hitface = face; nuclear@1: } nuclear@1: } nuclear@1: } nuclear@1: } nuclear@1: nuclear@1: if(nearest_hit.obj) { nuclear@1: if(hit) { nuclear@1: *hit = nearest_hit; nuclear@1: nuclear@1: // if we are interested in the mesh and not the faces set obj to this nuclear@1: if(Mesh::intersect_mode & ISECT_FACE) { nuclear@1: hit->obj = &hitface; nuclear@1: } else if(Mesh::intersect_mode & ISECT_VERTICES) { nuclear@1: hit->obj = &hitvert; nuclear@1: } else { nuclear@1: hit->obj = this; nuclear@1: } nuclear@1: } nuclear@1: return true; nuclear@1: } nuclear@1: return false; nuclear@1: }*/ nuclear@1: nuclear@1: nuclear@1: // ------ private member functions ------ nuclear@1: nuclear@1: void Mesh::calc_aabb() nuclear@1: { nuclear@1: // the cast is to force calling the const version which doesn't invalidate nuclear@1: if(!((const Mesh*)this)->get_attrib_data(MESH_ATTR_VERTEX)) { nuclear@1: return; nuclear@1: } nuclear@1: nuclear@1: aabb.min = Vector3(FLT_MAX, FLT_MAX, FLT_MAX); nuclear@1: aabb.max = -aabb.min; nuclear@1: nuclear@1: for(unsigned int i=0; i aabb.max[j]) { nuclear@1: aabb.max[j] = v[j]; nuclear@1: } nuclear@1: } nuclear@1: } nuclear@1: aabb_valid = true; nuclear@1: } nuclear@1: nuclear@1: void Mesh::calc_bsph() nuclear@1: { nuclear@1: // the cast is to force calling the const version which doesn't invalidate nuclear@1: if(!((const Mesh*)this)->get_attrib_data(MESH_ATTR_VERTEX)) { nuclear@1: return; nuclear@1: } nuclear@1: nuclear@1: Vector3 v; nuclear@1: bsph.center = Vector3(0, 0, 0); nuclear@1: nuclear@1: // first find the center nuclear@1: for(unsigned int i=0; i bsph.radius) { nuclear@1: bsph.radius = dist_sq; nuclear@1: } nuclear@1: } nuclear@1: bsph.radius = sqrt(bsph.radius); nuclear@1: nuclear@1: bsph_valid = true; nuclear@1: } nuclear@1: #endif nuclear@1: nuclear@1: void Mesh::update_buffers() nuclear@1: { nuclear@1: for(int i=0; iget_index_data(); nuclear@1: nuclear@1: for(unsigned int i=0; icalc_normal(); nuclear@1: } nuclear@1: return normal; nuclear@1: } nuclear@1: nuclear@1: void Triangle::transform(const Matrix4x4 &xform) nuclear@1: { nuclear@1: v[0].transform(xform); nuclear@1: v[1].transform(xform); nuclear@1: v[2].transform(xform); nuclear@1: normal_valid = false; nuclear@1: } nuclear@1: nuclear@1: void Triangle::draw() const nuclear@1: { nuclear@1: Vector3 n[3]; nuclear@1: n[0] = get_normal(); nuclear@1: n[1] = get_normal(); nuclear@1: n[2] = get_normal(); nuclear@1: nuclear@1: int vloc = Mesh::get_attrib_location(MESH_ATTR_VERTEX); nuclear@1: int nloc = Mesh::get_attrib_location(MESH_ATTR_NORMAL); nuclear@1: nuclear@1: glEnableVertexAttribArray(vloc); nuclear@1: glVertexAttribPointer(vloc, 3, GL_FLOAT, GL_FALSE, 0, &v[0].x); nuclear@1: glVertexAttribPointer(nloc, 3, GL_FLOAT, GL_FALSE, 0, &n[0].x); nuclear@1: nuclear@1: glDrawArrays(GL_TRIANGLES, 0, 3); nuclear@1: nuclear@1: glDisableVertexAttribArray(vloc); nuclear@1: glDisableVertexAttribArray(nloc); nuclear@1: CHECKGLERR; nuclear@1: } nuclear@1: nuclear@1: void Triangle::draw_wire() const nuclear@1: { nuclear@1: static const int idxarr[] = {0, 1, 1, 2, 2, 0}; nuclear@1: int vloc = Mesh::get_attrib_location(MESH_ATTR_VERTEX); nuclear@1: nuclear@1: glEnableVertexAttribArray(vloc); nuclear@1: glVertexAttribPointer(vloc, 3, GL_FLOAT, GL_FALSE, 0, &v[0].x); nuclear@1: nuclear@1: glDrawElements(GL_LINES, 6, GL_UNSIGNED_INT, idxarr); nuclear@1: nuclear@1: glDisableVertexAttribArray(vloc); nuclear@1: CHECKGLERR; nuclear@1: } nuclear@1: nuclear@1: Vector3 Triangle::calc_barycentric(const Vector3 &pos) const nuclear@1: { nuclear@1: Vector3 norm = get_normal(); nuclear@1: nuclear@1: float area_sq = fabs(dot_product(cross_product(v[1] - v[0], v[2] - v[0]), norm)); nuclear@1: if(area_sq < 1e-5) { nuclear@1: return Vector3(0, 0, 0); nuclear@1: } nuclear@1: nuclear@1: float asq0 = fabs(dot_product(cross_product(v[1] - pos, v[2] - pos), norm)); nuclear@1: float asq1 = fabs(dot_product(cross_product(v[2] - pos, v[0] - pos), norm)); nuclear@1: float asq2 = fabs(dot_product(cross_product(v[0] - pos, v[1] - pos), norm)); nuclear@1: nuclear@1: return Vector3(asq0 / area_sq, asq1 / area_sq, asq2 / area_sq); nuclear@1: } nuclear@1: nuclear@1: /*bool Triangle::intersect(const Ray &ray, HitPoint *hit) const nuclear@1: { nuclear@1: Vector3 normal = get_normal(); nuclear@1: nuclear@1: float ndotdir = dot_product(ray.dir, normal); nuclear@1: if(fabs(ndotdir) < 1e-4) { nuclear@1: return false; nuclear@1: } nuclear@1: nuclear@1: Vector3 vertdir = v[0] - ray.origin; nuclear@1: float t = dot_product(normal, vertdir) / ndotdir; nuclear@1: nuclear@1: Vector3 pos = ray.origin + ray.dir * t; nuclear@1: Vector3 bary = calc_barycentric(pos); nuclear@1: nuclear@1: if(bary.x + bary.y + bary.z > 1.00001) { nuclear@1: return false; nuclear@1: } nuclear@1: nuclear@1: if(hit) { nuclear@1: hit->dist = t; nuclear@1: hit->pos = ray.origin + ray.dir * t; nuclear@1: hit->normal = normal; nuclear@1: hit->obj = this; nuclear@1: } nuclear@1: return true; nuclear@1: }*/