Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DT_Object.h « src « solid « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 78beee2ab57597f9e5928057065d23ca45626acc (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
/*
 * SOLID - Software Library for Interference Detection
 * 
 * Copyright (C) 2001-2003  Dtecta.  All rights reserved.
 *
 * This library may be distributed under the terms of the Q Public License
 * (QPL) as defined by Trolltech AS of Norway and appearing in the file
 * LICENSE.QPL included in the packaging of this file.
 *
 * This library may be distributed and/or modified under the terms of the
 * GNU General Public License (GPL) version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 *
 * This library is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Commercial use or any other use of this library not covered by either 
 * the QPL or the GPL requires an additional license from Dtecta. 
 * Please contact info@dtecta.com for enquiries about the terms of commercial
 * use of this library.
 */

#ifndef DT_OBJECT_H
#define DT_OBJECT_H

#include <vector>

#include "SOLID.h"
#include "SOLID_broad.h"

#include "MT_Transform.h"
#include "MT_Quaternion.h"
#include "MT_BBox.h"
#include "DT_Shape.h"

class DT_Convex;

class DT_Object {
public:
    DT_Object(void *client_object, const DT_Shape& shape) :
		m_client_object(client_object),
		m_shape(shape), 
		m_margin(MT_Scalar(0.0))
	{
		m_xform.setIdentity();
		setBBox();
	}

	void setMargin(MT_Scalar margin) 
	{ 
		m_margin = margin; 
		setBBox();
	}

	void setScaling(const MT_Vector3& scaling)
	{
        m_xform.scale(scaling);
        setBBox();
    }

    void setPosition(const MT_Point3& pos) 
	{ 
        m_xform.setOrigin(pos);
        setBBox();
    }
    
    void setOrientation(const MT_Quaternion& orn)
	{
		m_xform.setRotation(orn);
		setBBox();
    }

	void setMatrix(const float *m) 
	{
        m_xform.setValue(m);
		assert(m_xform.getBasis().determinant() != MT_Scalar(0.0));
        setBBox();
    }

    void setMatrix(const double *m)
	{
        m_xform.setValue(m);
		assert(m_xform.getBasis().determinant() != MT_Scalar(0.0));
        setBBox();
    }

    void getMatrix(float *m) const
	{
        m_xform.getValue(m);
    }

    void getMatrix(double *m) const 
	{
        m_xform.getValue(m);
    }

	void setBBox();

	const MT_BBox& getBBox() const { return m_bbox; }	
	
    DT_ResponseClass getResponseClass() const { return m_responseClass; }
    
	void setResponseClass(DT_ResponseClass responseClass) 
	{ 
		m_responseClass = responseClass;
	}

    DT_ShapeType getType() const { return m_shape.getType(); }

    void *getClientObject() const { return m_client_object; }

	bool ray_cast(const MT_Point3& source, const MT_Point3& target, 
				  MT_Scalar& param, MT_Vector3& normal) const; 

	void addProxy(BP_ProxyHandle proxy) { m_proxies.push_back(proxy); }

	void removeProxy(BP_ProxyHandle proxy) 
	{ 
		T_ProxyList::iterator it = std::find(m_proxies.begin(), m_proxies.end(), proxy);
		if (it != m_proxies.end()) {
			m_proxies.erase(it);
		}
	}


	friend bool intersect(const DT_Object&, const DT_Object&, MT_Vector3& v);
	
	friend bool common_point(const DT_Object&, const DT_Object&, MT_Vector3&, 
							 MT_Point3&, MT_Point3&);
	
	friend bool penetration_depth(const DT_Object&, const DT_Object&, 
								  MT_Vector3&, MT_Point3&, MT_Point3&);
	
	friend MT_Scalar closest_points(const DT_Object&, const DT_Object&, 
									MT_Point3&, MT_Point3&);

private:
	typedef std::vector<BP_ProxyHandle> T_ProxyList;

	void              *m_client_object;
	DT_ResponseClass   m_responseClass;
    const DT_Shape&    m_shape;
    MT_Scalar          m_margin;
	MT_Transform       m_xform;
	T_ProxyList		   m_proxies;
	MT_BBox            m_bbox;
};

#endif