Commit 99ffd7c3 authored by Dave Griffiths's avatar Dave Griffiths
Browse files

bb intersection fix

parent df08c096
......@@ -75,7 +75,18 @@
(translate (vector 2 -6 0))
(texture 0)
(identity)
(define a (build-cube))
(define b (with-state (parent a) (build-cube)))
(define c (build-cube))
(with-primitive b (parent c))
(with-primitive
a
(recalc-bb)
(msg "bb/point-intersect? 1=" (bb/point-intersect? (vector 0 0 0) 0))
(msg "bb/point-intersect? 0=" (bb/point-intersect? (vector 10 0 0) 0))
(translate (vector 10 0 0))
(msg "bb/point-intersect? 1=" (bb/point-intersect? (vector 10 0 0) 0))
)
......@@ -526,7 +526,7 @@ bool engine::bb_point_intersect(const vec3 &p, flx_real threshold)
scenenode *n = grabbed_node();
if (n && n->m_primitive!=NULL)
{
vec3 pt=n->m_tx.transform(p);
vec3 pt=n->m_tx.inverse().transform(p);
return n->m_primitive->intersect_bb(pt,threshold);
}
}
......
......@@ -25,7 +25,8 @@
#include "cube.h"
primitive::primitive(unsigned int size, type t)
primitive::primitive(unsigned int size, type t) :
m_bb_empty(true)
{
#ifndef _EE
switch (t)
......@@ -57,7 +58,8 @@ void primitive::build()
m_tex=get_pdata_arr("t");
}
primitive::primitive()
primitive::primitive():
m_bb_empty(true)
{
m_size=12*3;
#ifndef _EE
......@@ -172,14 +174,26 @@ void primitive::recalc_bb()
{
for (int i=0; i<m_size; i++)
{
if (m_bbmin>m_positions[i]) m_bbmin=m_positions[i];
if (m_bbmax<m_positions[i]) m_bbmax=m_positions[i];
if (m_bb_empty)
{
m_bbmin=m_positions[i];
m_bbmax=m_positions[i];
m_bb_empty=false;
}
if (m_positions[i].x<m_bbmin.x) m_bbmin.x=m_positions[i].x;
if (m_positions[i].y<m_bbmin.y) m_bbmin.y=m_positions[i].y;
if (m_positions[i].z<m_bbmin.z) m_bbmin.z=m_positions[i].z;
if (m_positions[i].x>=m_bbmax.x) m_bbmax.x=m_positions[i].x;
if (m_positions[i].y>=m_bbmax.y) m_bbmax.y=m_positions[i].y;
if (m_positions[i].z>=m_bbmax.z) m_bbmax.z=m_positions[i].z;
}
}
bool primitive::intersect_bb(const vec3 &p, flx_real threshold)
{
return intersect_point_bb(p, m_bbmin, m_bbmin, threshold);
return intersect_point_bb(p, m_bbmin, m_bbmax, threshold);
}
list *primitive::intersect(const vec3 &start, const vec3 &end)
......
......@@ -69,6 +69,7 @@ protected:
u32 m_size;
list m_pdata;
bool m_bb_empty;
vec3 m_bbmin;
vec3 m_bbmax;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment