520389e3
xiaoyu
接入cocos源码,编译未通过,继续修改
|
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
|
/**
Copyright 2013 BlackBerry Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Original file from GamePlay3D: http://gameplay3d.org
This file was modified to fit the cocos2d-x project
*/
#include "math/Vec3.h"
#include "math/Mat4.h"
NS_CC_MATH_BEGIN
inline bool Vec3::isZero() const
{
return x == 0.0f && y == 0.0f && z == 0.0f;
}
inline bool Vec3::isOne() const
{
return x == 1.0f && y == 1.0f && z == 1.0f;
}
inline void Vec3::add(const Vec3& v)
{
x += v.x;
y += v.y;
z += v.z;
}
inline void Vec3::add(float xx, float yy, float zz)
{
x += xx;
y += yy;
z += zz;
}
inline float Vec3::length() const
{
return std::sqrt(x * x + y * y + z * z);
}
inline float Vec3::lengthSquared() const
{
return (x * x + y * y + z * z);
}
inline void Vec3::negate()
{
x = -x;
y = -y;
z = -z;
}
inline void Vec3::scale(float scalar)
{
x *= scalar;
y *= scalar;
z *= scalar;
}
inline Vec3 Vec3::lerp(const Vec3 &target, float alpha) const
{
return *this * (1.f - alpha) + target * alpha;
}
inline void Vec3::set(float xx, float yy, float zz)
{
this->x = xx;
this->y = yy;
this->z = zz;
}
inline void Vec3::set(const float* array)
{
GP_ASSERT(array);
x = array[0];
y = array[1];
z = array[2];
}
inline void Vec3::set(const Vec3& v)
{
this->x = v.x;
this->y = v.y;
this->z = v.z;
}
inline void Vec3::set(const Vec3& p1, const Vec3& p2)
{
x = p2.x - p1.x;
y = p2.y - p1.y;
z = p2.z - p1.z;
}
inline void Vec3::setZero()
{
x = y = z = 0.0f;
}
inline void Vec3::subtract(const Vec3& v)
{
x -= v.x;
y -= v.y;
z -= v.z;
}
inline Vec3 Vec3::operator+(const Vec3& v) const
{
Vec3 result(*this);
result.add(v);
return result;
}
inline Vec3& Vec3::operator+=(const Vec3& v)
{
add(v);
return *this;
}
inline Vec3 Vec3::operator-(const Vec3& v) const
{
Vec3 result(*this);
result.subtract(v);
return result;
}
inline Vec3& Vec3::operator-=(const Vec3& v)
{
subtract(v);
return *this;
}
inline Vec3 Vec3::operator-() const
{
Vec3 result(*this);
result.negate();
return result;
}
inline Vec3 Vec3::operator*(float s) const
{
Vec3 result(*this);
result.scale(s);
return result;
}
inline Vec3& Vec3::operator*=(float s)
{
scale(s);
return *this;
}
inline Vec3 Vec3::operator/(const float s) const
{
return Vec3(this->x / s, this->y / s, this->z / s);
}
inline bool Vec3::operator==(const Vec3& v) const
{
return x==v.x && y==v.y && z==v.z;
}
inline bool Vec3::operator!=(const Vec3& v) const
{
return x!=v.x || y!=v.y || z!=v.z;
}
inline Vec3 operator*(float x, const Vec3& v)
{
Vec3 result(v);
result.scale(x);
return result;
}
NS_CC_MATH_END
|