CCDeprecated.cpp
11.3 KB
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "scripting/deprecated/CCDeprecated.h"
#include "platform/CCPlatformMacros.h"
#include "math/Vec2.h"
#include "math/CCGeometry.h"
#include "base/ccTypes.h"
#include "base/CCDirector.h"
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif _MSC_VER >= 1400 //vs 2005 or higher
#pragma warning (push)
#pragma warning (disable: 4996)
#endif
NS_CC_BEGIN
const Vec2 CCPointZero;
/* The "zero" size -- equivalent to Size(0, 0). */
const Size CCSizeZero = Size::ZERO;
/* The "zero" rectangle -- equivalent to Rect(0, 0, 0, 0). */
const Rect CCRectZero = Rect::ZERO;
const Color3B ccWHITE = Color3B::WHITE;
const Color3B ccYELLOW = Color3B::YELLOW;
const Color3B ccGREEN = Color3B::GREEN;
const Color3B ccBLUE = Color3B::BLUE;
const Color3B ccRED = Color3B::RED;
const Color3B ccMAGENTA = Color3B::MAGENTA;
const Color3B ccBLACK = Color3B::BLACK;
const Color3B ccORANGE = Color3B::ORANGE;
const Color3B ccGRAY = Color3B::GRAY;
const BlendFunc kCCBlendFuncDisable = BlendFunc::DISABLE;
MATRIX_STACK_TYPE currentActiveStackType = MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW;
void CC_DLL kmGLFreeAll()
{
Director::getInstance()->resetMatrixStack();
}
void CC_DLL kmGLPushMatrix()
{
Director::getInstance()->pushMatrix(currentActiveStackType);
}
void CC_DLL kmGLPopMatrix()
{
Director::getInstance()->popMatrix(currentActiveStackType);
}
void CC_DLL kmGLMatrixMode(unsigned int mode)
{
if(KM_GL_MODELVIEW == mode)
currentActiveStackType = MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW;
else if(KM_GL_PROJECTION == mode)
currentActiveStackType = MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION;
else if(KM_GL_TEXTURE == mode)
currentActiveStackType = MATRIX_STACK_TYPE::MATRIX_STACK_TEXTURE;
else
{
CC_ASSERT(false);
}
}
void CC_DLL kmGLLoadIdentity()
{
Director::getInstance()->loadIdentityMatrix(currentActiveStackType);
}
void CC_DLL kmGLLoadMatrix(const Mat4* pIn)
{
Director::getInstance()->loadMatrix(currentActiveStackType, *pIn);
}
void CC_DLL kmGLMultMatrix(const Mat4* pIn)
{
Director::getInstance()->multiplyMatrix(currentActiveStackType, *pIn);
}
void CC_DLL kmGLTranslatef(float x, float y, float z)
{
Mat4 mat;
Mat4::createTranslation(Vec3(x, y, z), &mat);
Director::getInstance()->multiplyMatrix(currentActiveStackType, mat);
}
void CC_DLL kmGLRotatef(float angle, float x, float y, float z)
{
Mat4 mat;
Mat4::createRotation(Vec3(x, y, z), angle, &mat);
Director::getInstance()->multiplyMatrix(currentActiveStackType, mat);
}
void CC_DLL kmGLScalef(float x, float y, float z)
{
Mat4 mat;
Mat4::createScale(x, y, z, &mat);
Director::getInstance()->multiplyMatrix(currentActiveStackType, mat);
}
void CC_DLL kmGLGetMatrix(unsigned int mode, Mat4* pOut)
{
if(KM_GL_MODELVIEW == mode)
*pOut = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
else if(KM_GL_PROJECTION == mode)
*pOut = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
else if(KM_GL_TEXTURE == mode)
*pOut = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_TEXTURE);
else
{
CC_ASSERT(false);
}
}
Mat4* kmMat4Fill(Mat4* pOut, const float* pMat)
{
pOut->set(pMat);
return pOut;
}
Mat4* kmMat4Assign(Mat4* pOut, const Mat4* pIn)
{
pOut->set(pIn->m);
return pOut;
}
Mat4* kmMat4Identity(Mat4* pOut)
{
*pOut = Mat4::IDENTITY;
return pOut;
}
Mat4* kmMat4Inverse(Mat4* pOut, const Mat4* pM)
{
*pOut = pM->getInversed();
return pOut;
}
Mat4* kmMat4Transpose(Mat4* pOut, const Mat4* pIn)
{
*pOut = pIn->getTransposed();
return pOut;
}
Mat4* kmMat4Multiply(Mat4* pOut, const Mat4* pM1, const Mat4* pM2)
{
*pOut = (*pM1) * (*pM2);
return pOut;
}
Mat4* kmMat4Translation(Mat4* pOut, const float x, const float y, const float z)
{
Mat4::createTranslation(x, y, z, pOut);
return pOut;
}
Mat4* kmMat4RotationX(Mat4* pOut, const float radians)
{
Mat4::createRotationX(radians, pOut);
return pOut;
}
Mat4* kmMat4RotationY(Mat4* pOut, const float radians)
{
Mat4::createRotationY(radians, pOut);
return pOut;
}
Mat4* kmMat4RotationZ(Mat4* pOut, const float radians)
{
Mat4::createRotationZ(radians, pOut);
return pOut;
}
Mat4* kmMat4RotationAxisAngle(Mat4* pOut, const Vec3* axis, float radians)
{
Mat4::createRotation(*axis, radians, pOut);
return pOut;
}
Mat4* kmMat4Scaling(Mat4* pOut, const float x, const float y, const float z)
{
Mat4::createScale(x, y, z, pOut);
return pOut;
}
Mat4* kmMat4PerspectiveProjection(Mat4* pOut, float fovY, float aspect, float zNear, float zFar)
{
Mat4::createPerspective(fovY, aspect, zNear, zFar, pOut);
return pOut;
}
Mat4* kmMat4OrthographicProjection(Mat4* pOut, float left, float right, float bottom, float top, float nearVal, float farVal)
{
Mat4::createOrthographicOffCenter(left, right, bottom, top, nearVal, farVal, pOut);
return pOut;
}
Mat4* kmMat4LookAt(Mat4* pOut, const Vec3* pEye, const Vec3* pCenter, const Vec3* pUp)
{
Mat4::createLookAt(*pEye, *pCenter, *pUp, pOut);
return pOut;
}
Vec3* kmVec3Fill(Vec3* pOut, float x, float y, float z)
{
pOut->x = x;
pOut->y = y;
pOut->z = z;
return pOut;
}
float kmVec3Length(const Vec3* pIn)
{
return pIn->length();
}
float kmVec3LengthSq(const Vec3* pIn)
{
return pIn->lengthSquared();
}
CC_DLL Vec3* kmVec3Lerp(Vec3* pOut, const Vec3* pV1, const Vec3* pV2, float t)
{
pOut->x = pV1->x + t * ( pV2->x - pV1->x );
pOut->y = pV1->y + t * ( pV2->y - pV1->y );
pOut->z = pV1->z + t * ( pV2->z - pV1->z );
return pOut;
}
Vec3* kmVec3Normalize(Vec3* pOut, const Vec3* pIn)
{
*pOut = pIn->getNormalized();
return pOut;
}
Vec3* kmVec3Cross(Vec3* pOut, const Vec3* pV1, const Vec3* pV2)
{
Vec3::cross(*pV1, *pV2, pOut);
return pOut;
}
float kmVec3Dot(const Vec3* pV1, const Vec3* pV2)
{
return Vec3::dot(*pV1, *pV2);
}
Vec3* kmVec3Add(Vec3* pOut, const Vec3* pV1, const Vec3* pV2)
{
Vec3::add(*pV1, *pV2, pOut);
return pOut;
}
Vec3* kmVec3Subtract(Vec3* pOut, const Vec3* pV1, const Vec3* pV2)
{
Vec3::subtract(*pV1, *pV2, pOut);
return pOut;
}
Vec3* kmVec3Transform(Vec3* pOut, const Vec3* pV1, const Mat4* pM)
{
pM->transformPoint(*pV1, pOut);
return pOut;
}
Vec3* kmVec3TransformNormal(Vec3* pOut, const Vec3* pV, const Mat4* pM)
{
pM->transformVector(*pV, pOut);
return pOut;
}
Vec3* kmVec3TransformCoord(Vec3* pOut, const Vec3* pV, const Mat4* pM)
{
Vec4 v(pV->x, pV->y, pV->z, 1);
pM->transformVector(&v);
v = v * (1/v.w);
pOut->set(v.x, v.y, v.z);
return pOut;
}
Vec3* kmVec3Scale(Vec3* pOut, const Vec3* pIn, const float s)
{
*pOut = *pIn * s;
return pOut;
}
Vec3* kmVec3Assign(Vec3* pOut, const Vec3* pIn)
{
*pOut = *pIn;
return pOut;
}
Vec3* kmVec3Zero(Vec3* pOut)
{
pOut->set(0, 0, 0);
return pOut;
}
Vec2* kmVec2Fill(Vec2* pOut, float x, float y)
{
pOut->set(x, y);
return pOut;
}
float kmVec2Length(const Vec2* pIn)
{
return pIn->length();
}
float kmVec2LengthSq(const Vec2* pIn)
{
return pIn->lengthSquared();
}
Vec2* kmVec2Normalize(Vec2* pOut, const Vec2* pIn)
{
*pOut = pIn->getNormalized();
return pOut;
}
Vec2* kmVec2Lerp(Vec2* pOut, const Vec2* pV1, const Vec2* pV2, float t)
{
pOut->x = pV1->x + t * ( pV2->x - pV1->x );
pOut->y = pV1->y + t * ( pV2->y - pV1->y );
return pOut;
}
Vec2* kmVec2Add(Vec2* pOut, const Vec2* pV1, const Vec2* pV2)
{
Vec2::add(*pV1, *pV2, pOut);
return pOut;
}
float kmVec2Dot(const Vec2* pV1, const Vec2* pV2)
{
return Vec2::dot(*pV1, *pV2);
}
Vec2* kmVec2Subtract(Vec2* pOut, const Vec2* pV1, const Vec2* pV2)
{
Vec2::subtract(*pV1, *pV2, pOut);
return pOut;
}
Vec2* kmVec2Scale(Vec2* pOut, const Vec2* pIn, const float s)
{
*pOut = *pIn * s;
return pOut;
}
Vec2* kmVec2Assign(Vec2* pOut, const Vec2* pIn)
{
*pOut = *pIn;
return pOut;
}
Vec4* kmVec4Fill(Vec4* pOut, float x, float y, float z, float w)
{
pOut->set(x, y, z, w);
return pOut;
}
Vec4* kmVec4Add(Vec4* pOut, const Vec4* pV1, const Vec4* pV2)
{
Vec4::add(*pV1, *pV2, pOut);
return pOut;
}
float kmVec4Dot(const Vec4* pV1, const Vec4* pV2)
{
return Vec4::dot(*pV1, *pV2);
}
float kmVec4Length(const Vec4* pIn)
{
return pIn->length();
}
float kmVec4LengthSq(const Vec4* pIn)
{
return pIn->lengthSquared();
}
Vec4* kmVec4Lerp(Vec4* pOut, const Vec4* pV1, const Vec4* pV2, float t)
{
pOut->x = pV1->x + t * ( pV2->x - pV1->x );
pOut->y = pV1->y + t * ( pV2->y - pV1->y );
pOut->z = pV1->z + t * ( pV2->z - pV1->z );
pOut->w = pV1->w + t * ( pV2->w - pV1->w );
return pOut;
}
Vec4* kmVec4Normalize(Vec4* pOut, const Vec4* pIn)
{
*pOut = pIn->getNormalized();
return pOut;
}
Vec4* kmVec4Scale(Vec4* pOut, const Vec4* pIn, const float s)
{
*pOut = *pIn * s;
return pOut;
}
Vec4* kmVec4Subtract(Vec4* pOut, const Vec4* pV1, const Vec4* pV2)
{
Vec4::subtract(*pV1, *pV2, pOut);
return pOut;
}
Vec4* kmVec4Assign(Vec4* pOut, const Vec4* pIn)
{
*pOut = *pIn;
return pOut;
}
Vec4* kmVec4MultiplyMat4(Vec4* pOut, const Vec4* pV, const Mat4* pM)
{
pM->transformVector(*pV, pOut);
return pOut;
}
Vec4* kmVec4Transform(Vec4* pOut, const Vec4* pV, const Mat4* pM)
{
pM->transformVector(*pV, pOut);
return pOut;
}
const Vec3 KM_VEC3_NEG_Z(0, 0, -1);
const Vec3 KM_VEC3_POS_Z(0, 0, 1);
const Vec3 KM_VEC3_POS_Y(0, 1, 0);
const Vec3 KM_VEC3_NEG_Y(0, -1, 0);
const Vec3 KM_VEC3_NEG_X(-1, 0, 0);
const Vec3 KM_VEC3_POS_X(1, 0, 0);
const Vec3 KM_VEC3_ZERO(0, 0, 0);
const Vec2 KM_VEC2_POS_Y(0, 1);
const Vec2 KM_VEC2_NEG_Y(0, -1);
const Vec2 KM_VEC2_NEG_X(-1, 0);
const Vec2 KM_VEC2_POS_X(1, 0);
const Vec2 KM_VEC2_ZERO(0, 0);
NS_CC_END
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
#elif _MSC_VER >= 1400 //vs 2005 or higher
#pragma warning (pop)
#endif