summaryrefslogtreecommitdiffstats
path: root/o3d/plugin/idl/bounding_box.idl
blob: 9a5cc82e897b75701697c8b1122f148d4d15b987 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
 * Copyright 2009, Google Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *     * Neither the name of Google Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

// TODO: some how make this file conditionally compile different for C++
//     vs Javascript like with #ifdef CPLUSPLUS etc..
namespace o3d {

%[
  A BoundingBox represents an Axis Aligned Bounding Box.
%]
[binding_model=by_value, marshaled, nocpp, include="core/cross/bounding_box.h", no_marshaled_docs]
class BoundingBox {
  %[
    Creates BoundingBox from min_extent and max_extent
    \param min_extent minimum extent of the box.
    \param max_extent maximum extent of the box.
  %]
  BoundingBox(Vectormath::Aos::Point3 min_extent,
              Vectormath::Aos::Point3 max_extent);

  %[
    Assigns a JavaScript array of arrays of numbers into a BoundingBox.
    This property is implicitly invoked whenever such an array is assigned to
    a BoundingBox property or such an array is passed as a BoundingBox method
    parameter.
  %]
  [plugin_data, userglue, userglue_setter, setter, nodocs]
  float[][] marshaled;

  %[
    True if this boundingbox has been initialized.
  %]
  [getter] bool valid_;

  %[
    The min extent of the box.
  %]
  [getter] Vectormath::Aos::Point3 min_extent;

  %[
    The max extent of the box.
  %]
  [getter] Vectormath::Aos::Point3 max_extent;

  %[
    Multiplies the bounding box by the given matrix returning a new bounding
    box.
    \param matrix The matrix to multiply by.
    \return The new bounding box.
  %]
  [const, userglue] BoundingBox Mul(Vectormath::Aos::Matrix4 matrix);

  %[
    Adds a bounding box to this bounding box returning a bounding box that
    encompases both.
    \param box BoundingBox to add to this BoundingBox.
    \return The new bounding box.
  %]
  [const, userglue] BoundingBox Add(BoundingBox box);

  %[
    Checks if a ray defined in same coordinate system as this box intersects
    this bounding box.
    \param start position of start of ray in local space.
    \param end position of end of ray in local space.
    \return RayIntersectionInfo. If result.value is false then something was
          wrong like using this function with an uninitialized bounding box. If
          result.intersected is true then the ray intersected the box
          and result.position is the exact point of intersection.
  %]
  [const, userglue]
  o3d::RayIntersectionInfo IntersectRay(Vectormath::Aos::Point3 start,
                                        Vectormath::Aos::Point3 end);

  %[
    Checks if a ray defined in same coordinate system as this box intersects
    this bounding box.
    \param startX The x coordinate of start of ray in local space.
    \param startY The y coordinate of start of ray in local space.
    \param startZ The z coordinate of start of ray in local space.
    \param endX The x coordinate of end of ray in local space.
    \param endY The y coordinate of end of ray in local space.
    \param endZ The z coordinate of end of ray in local space.
    \return RayIntersectionInfo. If result.value is false then something was
          wrong like using this function with an uninitialized bounding box. If
          result.intersected is true then the ray intersected the box
          and result.position is the exact point of intersection.
  %]
  [const, userglue]
  o3d::RayIntersectionInfo IntersectRay(float startX,
                                        float startY,
                                        float startZ,
                                        float endX,
                                        float endY,
                                        float endZ);

  %[
   Returns true if the bounding box is inside the frustum.
   \param matrix Matrix to transform the box from its local space to view
       frustum space.
   \return True if the box is in the frustum.
  %]
  [const] bool InFrustum(Vectormath::Aos::Matrix4 matrix);

  [verbatim=cpp_glue] %{
    void userglue_setter_marshaled(
        void* plugin_data,
        o3d::BoundingBox* _this,
        const std::vector<std::vector<float> >& values) {
      if (values.size() == 0) {
        *_this = o3d::BoundingBox();
      } else if (values.size() != 2) {
        o3d::ServiceLocator* service_locator =
            static_cast<glue::_o3d::PluginObject*>(
                plugin_data)->service_locator();
        O3D_ERROR(service_locator)
            << "BoundingBox: expected 2 values, got " << values.size();
      } else {
        for (std::vector<float>::size_type i = 0; i < values.size(); ++i) {
          if (values[i].size() != 3) {
            o3d::ServiceLocator* service_locator =
                static_cast<glue::_o3d::PluginObject*>(
                    plugin_data)->service_locator();
            O3D_ERROR(service_locator)
                << "BoundingBox: expected 3 values, got " << values.size();
            return;
          }
        }
        *_this = o3d::BoundingBox(
            Vectormath::Aos::Point3(values[0][0], values[0][1], values[0][2]),
            Vectormath::Aos::Point3(values[1][0], values[1][1], values[1][2]));
      }
    }
    o3d::BoundingBox userglue_method_Mul(
        o3d::BoundingBox* self,
        const Vectormath::Aos::Matrix4 &matrix) {
      o3d::BoundingBox bounding_box;
      self->Mul(matrix, &bounding_box);
      return bounding_box;
    }
    o3d::BoundingBox userglue_method_Add(
        o3d::BoundingBox* self,
        const o3d::BoundingBox& box) {
      o3d::BoundingBox result;
      self->Add(box, &result);
      return result;
    }
    o3d::RayIntersectionInfo userglue_method_IntersectRay(
      o3d::BoundingBox* self,
      const Vectormath::Aos::Point3& start,
      const Vectormath::Aos::Point3& end) {
      o3d::RayIntersectionInfo ray_intersection_info;
      self->IntersectRay(start, end, &ray_intersection_info);
      return ray_intersection_info;
    }
    o3d::RayIntersectionInfo userglue_method_IntersectRay(
        o3d::BoundingBox* self,
        float startX,
        float startY,
        float startZ,
        float endX,
        float endY,
        float endZ) {
      o3d::RayIntersectionInfo ray_intersection_info;
      self->IntersectRay(Vectormath::Aos::Point3(startX, startY, startZ),
                          Vectormath::Aos::Point3(endX, endY, endZ),
                          &ray_intersection_info);
      return ray_intersection_info;
    }
  %}
};  // BoundingBox

%[
  A Param which stores a BoundingBox.
%]
[nocpp, include="core/cross/param.h"] class ParamBoundingBox : Param {
  %[
    The BoundingBox stored by the Param.
  %]
  [getter, setter] BoundingBox value_;
};

}  // namespace o3d