~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/gameengine/SceneGraph/SG_Spatial.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: SG_Spatial.cpp,v 1.5 2004/04/24 06:40:15 kester Exp $
 
2
 * $Id: SG_Spatial.cpp,v 1.9 2004/10/16 11:41:50 kester Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
47
47
): 
48
48
 
49
49
        SG_IObject(clientobj,clientinfo,callbacks),
50
 
        m_localPosition(MT_Point3(0,0,0)),
51
 
        m_localRotation(1,0,0,0,1,0,0,0,1),
 
50
        m_localPosition(MT_Point3(0.0,0.0,0.0)),
 
51
        m_localRotation(MT_Matrix3x3(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0)),
52
52
        m_localScaling(MT_Vector3(1.f,1.f,1.f)),
 
53
        
 
54
        m_worldPosition(MT_Point3(0.0,0.0,0.0)),
 
55
        m_worldRotation(MT_Matrix3x3(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0)),
 
56
        m_worldScaling(MT_Vector3(1.f,1.f,1.f)),
 
57
 
53
58
        m_parent_relation (NULL),
54
 
 
55
 
        m_worldPosition(MT_Point3(0,0,0)),
56
 
        m_worldRotation(0,0,0,0,0,0,0,0,0),
57
 
        m_worldScaling(MT_Vector3(1.f,1.f,1.f))
58
 
 
 
59
        
 
60
        m_bbox(MT_Point3(-1.0, -1.0, -1.0), MT_Point3(1.0, 1.0, 1.0)),
 
61
        m_radius(1.0)
59
62
{
60
63
}
61
64
 
67
70
        m_localPosition(other.m_localPosition),
68
71
        m_localRotation(other.m_localRotation),
69
72
        m_localScaling(other.m_localScaling),
70
 
        m_parent_relation(NULL),
 
73
        
71
74
        m_worldPosition(other.m_worldPosition),
72
75
        m_worldRotation(other.m_worldRotation),
73
 
        m_worldScaling(other.m_worldScaling)
 
76
        m_worldScaling(other.m_worldScaling),
 
77
        
 
78
        m_parent_relation(NULL),
 
79
        
 
80
        m_bbox(other.m_bbox),
 
81
        m_radius(other.m_radius)
74
82
{
75
83
        // duplicate the parent relation for this object
76
84
        m_parent_relation = other.m_parent_relation->NewCopy();
98
106
 */
99
107
 
100
108
 
101
 
        void 
 
109
        bool 
102
110
SG_Spatial::
103
111
UpdateSpatialData(
104
112
        const SG_Spatial *parent,
114
122
 
115
123
        for (;cit!=c_end;++cit)
116
124
        {
117
 
                bComputesWorldTransform = bComputesWorldTransform || (*cit)->Update(time);
 
125
                if ((*cit)->Update(time))
 
126
                        bComputesWorldTransform = true;
118
127
        }
119
128
 
120
129
        // If none of the objects updated our values then we ask the
122
131
        // our world coordinates.
123
132
 
124
133
        if (!bComputesWorldTransform)
125
 
    {
126
 
                ComputeWorldTransforms(parent);
127
 
    }
 
134
                bComputesWorldTransform = ComputeWorldTransforms(parent);
 
135
 
 
136
        return bComputesWorldTransform;
128
137
}
129
138
 
130
 
void    SG_Spatial::ComputeWorldTransforms(const SG_Spatial *parent)
 
139
bool    SG_Spatial::ComputeWorldTransforms(const SG_Spatial *parent)
131
140
{
132
 
        m_parent_relation->UpdateChildCoordinates(this,parent);
 
141
        return m_parent_relation->UpdateChildCoordinates(this,parent);
133
142
}
134
143
 
135
 
 
136
144
/**
137
145
 * Position and translation methods
138
146
 */
285
293
        return m_worldScaling;
286
294
}
287
295
 
 
296
SG_BBox& SG_Spatial::BBox()
 
297
{
 
298
        return m_bbox;
 
299
}
 
300
 
 
301
void SG_Spatial::SetBBox(SG_BBox& bbox)
 
302
{
 
303
        m_bbox = bbox;
 
304
}
 
305
 
 
306
MT_Transform SG_Spatial::GetWorldTransform() const
 
307
{
 
308
        return MT_Transform(m_worldPosition, 
 
309
                m_worldRotation.scaled(
 
310
                m_worldScaling[0], m_worldScaling[1], m_worldScaling[2]));
 
311
}
 
312
 
 
313
bool SG_Spatial::inside(const MT_Point3 &point) const
 
314
{
 
315
        MT_Scalar radius = m_worldScaling[m_worldScaling.closestAxis()]*m_radius;
 
316
        return (m_worldPosition.distance2(point) <= radius*radius) ?
 
317
                m_bbox.transform(GetWorldTransform()).inside(point) :
 
318
                false;
 
319
}
 
320
 
 
321
void SG_Spatial::getBBox(MT_Point3 *box) const
 
322
{
 
323
        m_bbox.get(box, GetWorldTransform());
 
324
}
 
325
 
 
326
void SG_Spatial::getAABBox(MT_Point3 *box) const
 
327
{
 
328
        m_bbox.getaa(box, GetWorldTransform());
 
329
}
 
330