mirror of https://github.com/axmolengine/axmol.git
Merge branch 'v3' of github.com:lvlonggame/cocos2d-x into v3
This commit is contained in:
commit
23df00b0b9
|
@ -43,6 +43,7 @@ Animate3D* Animate3D::create(Animation3D* animation)
|
||||||
|
|
||||||
animate->autorelease();
|
animate->autorelease();
|
||||||
animate->setDuration(animation->getDuration());
|
animate->setDuration(animation->getDuration());
|
||||||
|
animate->setOriginInterval(animation->getDuration());
|
||||||
|
|
||||||
return animate;
|
return animate;
|
||||||
}
|
}
|
||||||
|
@ -58,6 +59,7 @@ Animate3D* Animate3D::create(Animation3D* animation, float fromTime, float durat
|
||||||
animate->_start = fromTime / fullDuration;
|
animate->_start = fromTime / fullDuration;
|
||||||
animate->_last = duration / fullDuration;
|
animate->_last = duration / fullDuration;
|
||||||
animate->setDuration(duration);
|
animate->setDuration(duration);
|
||||||
|
animate->setOriginInterval(duration);
|
||||||
|
|
||||||
return animate;
|
return animate;
|
||||||
}
|
}
|
||||||
|
@ -85,7 +87,7 @@ Animate3D* Animate3D::clone() const
|
||||||
copy->_last = _last;
|
copy->_last = _last;
|
||||||
copy->_playReverse = _playReverse;
|
copy->_playReverse = _playReverse;
|
||||||
copy->setDuration(animate->getDuration());
|
copy->setDuration(animate->getDuration());
|
||||||
|
copy->setOriginInterval(animate->getOriginInterval());
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +162,7 @@ void Animate3D::stop()
|
||||||
//! called every frame with it's delta time. DON'T override unless you know what you are doing.
|
//! called every frame with it's delta time. DON'T override unless you know what you are doing.
|
||||||
void Animate3D::step(float dt)
|
void Animate3D::step(float dt)
|
||||||
{
|
{
|
||||||
ActionInterval::step(dt * _absSpeed);
|
ActionInterval::step(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animate3D::update(float t)
|
void Animate3D::update(float t)
|
||||||
|
@ -238,6 +240,7 @@ void Animate3D::setSpeed(float speed)
|
||||||
{
|
{
|
||||||
_absSpeed = fabsf(speed);
|
_absSpeed = fabsf(speed);
|
||||||
_playReverse = speed < 0;
|
_playReverse = speed < 0;
|
||||||
|
_duration = _originInterval / _absSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animate3D::setWeight(float weight)
|
void Animate3D::setWeight(float weight)
|
||||||
|
@ -246,6 +249,11 @@ void Animate3D::setWeight(float weight)
|
||||||
_weight = fabsf(weight);
|
_weight = fabsf(weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Animate3D::setOriginInterval(float interval)
|
||||||
|
{
|
||||||
|
_originInterval = interval;
|
||||||
|
}
|
||||||
|
|
||||||
Animate3D::Animate3D()
|
Animate3D::Animate3D()
|
||||||
: _state(Animate3D::Animate3DState::Running)
|
: _state(Animate3D::Animate3DState::Running)
|
||||||
, _animation(nullptr)
|
, _animation(nullptr)
|
||||||
|
@ -256,6 +264,7 @@ Animate3D::Animate3D()
|
||||||
, _playReverse(false)
|
, _playReverse(false)
|
||||||
, _accTransTime(0.0f)
|
, _accTransTime(0.0f)
|
||||||
, _lastTime(0.0f)
|
, _lastTime(0.0f)
|
||||||
|
, _originInterval(0.0f)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,6 +85,10 @@ public:
|
||||||
float getWeight() const { return _weight; }
|
float getWeight() const { return _weight; }
|
||||||
void setWeight(float weight);
|
void setWeight(float weight);
|
||||||
|
|
||||||
|
/**get & set origin interval*/
|
||||||
|
void setOriginInterval(float interval);
|
||||||
|
float getOriginInterval() const {return _originInterval; }
|
||||||
|
|
||||||
/** animate transition time */
|
/** animate transition time */
|
||||||
static float getTransitionTime() { return _transTime; }
|
static float getTransitionTime() { return _transTime; }
|
||||||
|
|
||||||
|
@ -117,6 +121,7 @@ protected:
|
||||||
static float _transTime; //transition time from one animate3d to another
|
static float _transTime; //transition time from one animate3d to another
|
||||||
float _accTransTime; // acculate transition time
|
float _accTransTime; // acculate transition time
|
||||||
float _lastTime; // last t (0 - 1)
|
float _lastTime; // last t (0 - 1)
|
||||||
|
float _originInterval;// save origin interval time
|
||||||
std::unordered_map<Bone3D*, Animation3D::Curve*> _boneCurves; //weak ref
|
std::unordered_map<Bone3D*, Animation3D::Curve*> _boneCurves; //weak ref
|
||||||
|
|
||||||
//sprite animates
|
//sprite animates
|
||||||
|
|
|
@ -207,8 +207,14 @@ bool Bundle3D::loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeD
|
||||||
materialdatas.resetData();
|
materialdatas.resetData();
|
||||||
nodedatas.resetData();
|
nodedatas.resetData();
|
||||||
|
|
||||||
|
std::string mtlPath = "";
|
||||||
|
if (mtl_basepath)
|
||||||
|
mtlPath = mtl_basepath;
|
||||||
|
else
|
||||||
|
mtlPath = fullPath.substr(0, fullPath.find_last_of("\\/") + 1).c_str();
|
||||||
|
|
||||||
ObjLoader::shapes_t shapes;
|
ObjLoader::shapes_t shapes;
|
||||||
auto ret = ObjLoader::LoadObj(shapes, fullPath.c_str(), mtl_basepath);
|
auto ret = ObjLoader::LoadObj(shapes, fullPath.c_str(), mtlPath.c_str());
|
||||||
if (ret.empty())
|
if (ret.empty())
|
||||||
{
|
{
|
||||||
//fill data
|
//fill data
|
||||||
|
|
|
@ -38,75 +38,135 @@ Ray::~Ray()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Ray::intersects(const AABB& aabb) const
|
bool Ray::intersects(const AABB& box, float* distance) const
|
||||||
{
|
{
|
||||||
Vec3 ptOnPlane;
|
float lowt = 0.0f;
|
||||||
Vec3 min = aabb._min;
|
|
||||||
Vec3 max = aabb._max;
|
|
||||||
|
|
||||||
const Vec3& origin = _origin;
|
|
||||||
const Vec3& dir = _direction;
|
|
||||||
|
|
||||||
float t;
|
float t;
|
||||||
|
bool hit = false;
|
||||||
|
Vec3 hitpoint;
|
||||||
|
const Vec3& min = box._min;
|
||||||
|
const Vec3& max = box._max;
|
||||||
|
const Vec3& rayorig = _origin;
|
||||||
|
const Vec3& raydir = _direction;
|
||||||
|
|
||||||
if (dir.x != 0.f)
|
// Check origin inside first
|
||||||
{
|
if (rayorig > min && rayorig < max)
|
||||||
if (dir.x > 0)
|
|
||||||
t = (min.x - origin.x) / dir.x;
|
|
||||||
else
|
|
||||||
t = (max.x - origin.x) / dir.x;
|
|
||||||
|
|
||||||
if (t > 0.f)
|
|
||||||
{
|
|
||||||
ptOnPlane = origin + t * dir;
|
|
||||||
|
|
||||||
if (min.y < ptOnPlane.y && ptOnPlane.y < max.y && min.z < ptOnPlane.z && ptOnPlane.z < max.z)
|
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dir.y != 0.f)
|
// Check each face in turn, only check closest 3
|
||||||
|
// Min x
|
||||||
|
if (rayorig.x <= min.x && raydir.x > 0)
|
||||||
{
|
{
|
||||||
if (dir.y > 0)
|
t = (min.x - rayorig.x) / raydir.x;
|
||||||
t = (min.y - origin.y) / dir.y;
|
if (t >= 0)
|
||||||
else
|
|
||||||
t = (max.y - origin.y) / dir.y;
|
|
||||||
|
|
||||||
if (t > 0.f)
|
|
||||||
{
|
{
|
||||||
ptOnPlane = origin + t * dir;
|
// Substitute t back into ray and check bounds and dist
|
||||||
|
hitpoint = rayorig + raydir * t;
|
||||||
if (min.z < ptOnPlane.z && ptOnPlane.z < max.z && min.x < ptOnPlane.x && ptOnPlane.x < max.x)
|
if (hitpoint.y >= min.y && hitpoint.y <= max.y &&
|
||||||
|
hitpoint.z >= min.z && hitpoint.z <= max.z &&
|
||||||
|
(!hit || t < lowt))
|
||||||
{
|
{
|
||||||
return true;
|
hit = true;
|
||||||
|
lowt = t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Max x
|
||||||
if (dir.z != 0.f)
|
if (rayorig.x >= max.x && raydir.x < 0)
|
||||||
{
|
{
|
||||||
if (dir.z > 0)
|
t = (max.x - rayorig.x) / raydir.x;
|
||||||
t = (min.z - origin.z) / dir.z;
|
if (t >= 0)
|
||||||
else
|
|
||||||
t = (max.z - origin.z) / dir.z;
|
|
||||||
|
|
||||||
if (t > 0.f)
|
|
||||||
{
|
{
|
||||||
ptOnPlane = origin + t * dir;
|
// Substitute t back into ray and check bounds and dist
|
||||||
|
hitpoint = rayorig + raydir * t;
|
||||||
if (min.x < ptOnPlane.x && ptOnPlane.x < max.x && min.y < ptOnPlane.y && ptOnPlane.y < max.y)
|
if (hitpoint.y >= min.y && hitpoint.y <= max.y &&
|
||||||
|
hitpoint.z >= min.z && hitpoint.z <= max.z &&
|
||||||
|
(!hit || t < lowt))
|
||||||
{
|
{
|
||||||
return true;
|
hit = true;
|
||||||
|
lowt = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Min y
|
||||||
|
if (rayorig.y <= min.y && raydir.y > 0)
|
||||||
|
{
|
||||||
|
t = (min.y - rayorig.y) / raydir.y;
|
||||||
|
if (t >= 0)
|
||||||
|
{
|
||||||
|
// Substitute t back into ray and check bounds and dist
|
||||||
|
hitpoint = rayorig + raydir * t;
|
||||||
|
if (hitpoint.x >= min.x && hitpoint.x <= max.x &&
|
||||||
|
hitpoint.z >= min.z && hitpoint.z <= max.z &&
|
||||||
|
(!hit || t < lowt))
|
||||||
|
{
|
||||||
|
hit = true;
|
||||||
|
lowt = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Max y
|
||||||
|
if (rayorig.y >= max.y && raydir.y < 0)
|
||||||
|
{
|
||||||
|
t = (max.y - rayorig.y) / raydir.y;
|
||||||
|
if
|
||||||
|
|
||||||
|
|
||||||
|
(t >= 0)
|
||||||
|
{
|
||||||
|
// Substitute t back into ray and check bounds and dist
|
||||||
|
hitpoint = rayorig + raydir * t;
|
||||||
|
if (hitpoint.x >= min.x && hitpoint.x <= max.x &&
|
||||||
|
hitpoint.z >= min.z && hitpoint.z <= max.z &&
|
||||||
|
(!hit || t < lowt))
|
||||||
|
{
|
||||||
|
hit = true;
|
||||||
|
lowt = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Min z
|
||||||
|
if (rayorig.z <= min.z && raydir.z > 0)
|
||||||
|
{
|
||||||
|
t = (min.z - rayorig.z) / raydir.z;
|
||||||
|
if (t >= 0)
|
||||||
|
{
|
||||||
|
// Substitute t back into ray and check bounds and dist
|
||||||
|
hitpoint = rayorig + raydir * t;
|
||||||
|
if (hitpoint.x >= min.x && hitpoint.x <= max.x &&
|
||||||
|
hitpoint.y >= min.y && hitpoint.y <= max.y &&
|
||||||
|
(!hit || t < lowt))
|
||||||
|
{
|
||||||
|
hit = true;
|
||||||
|
lowt = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Max z
|
||||||
|
if (rayorig.z >= max.z && raydir.z < 0)
|
||||||
|
{
|
||||||
|
t = (max.z - rayorig.z) / raydir.z;
|
||||||
|
if (t >= 0)
|
||||||
|
{
|
||||||
|
// Substitute t back into ray and check bounds and dist
|
||||||
|
hitpoint = rayorig + raydir * t;
|
||||||
|
if (hitpoint.x >= min.x && hitpoint.x <= max.x &&
|
||||||
|
hitpoint.y >= min.y && hitpoint.y <= max.y &&
|
||||||
|
(!hit || t < lowt))
|
||||||
|
{
|
||||||
|
hit = true;
|
||||||
|
lowt = t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
if (distance)
|
||||||
|
*distance = lowt;
|
||||||
|
|
||||||
|
return hit;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Ray::intersects(const OBB& obb) const
|
bool Ray::intersects(const OBB& obb, float* distance) const
|
||||||
{
|
{
|
||||||
AABB aabb;
|
AABB aabb;
|
||||||
aabb._min = - obb._extents;
|
aabb._min = - obb._extents;
|
||||||
|
@ -137,7 +197,8 @@ bool Ray::intersects(const OBB& obb) const
|
||||||
|
|
||||||
ray.transform(mat);
|
ray.transform(mat);
|
||||||
|
|
||||||
return ray.intersects(aabb);
|
return ray.intersects(aabb, distance);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float Ray::dist(const Plane& plane) const
|
float Ray::dist(const Plane& plane) const
|
||||||
|
|
|
@ -59,14 +59,14 @@ public:
|
||||||
~Ray();
|
~Ray();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether this ray intersects the specified bounding box.
|
* Check whether this ray intersects with the specified AABB.
|
||||||
*/
|
*/
|
||||||
bool intersects(const AABB& aabb) const;
|
bool intersects(const AABB& aabb, float* distance = nullptr) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether this ray intersects the specified obb.
|
* Check whether this ray intersects with the specified OBB.
|
||||||
*/
|
*/
|
||||||
bool intersects(const OBB& obb) const;
|
bool intersects(const OBB& obb, float* distance = nullptr) const;
|
||||||
|
|
||||||
float dist(const Plane& plane) const;
|
float dist(const Plane& plane) const;
|
||||||
Vec3 intersects(const Plane& plane) const;
|
Vec3 intersects(const Plane& plane) const;
|
||||||
|
|
|
@ -362,6 +362,13 @@ public:
|
||||||
*/
|
*/
|
||||||
inline const Quaternion operator*(const Quaternion& q) const;
|
inline const Quaternion operator*(const Quaternion& q) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the quaternion product of this quaternion with the given vec3.
|
||||||
|
* @param v The vec3 to multiply.
|
||||||
|
* @return The vec3 product.
|
||||||
|
*/
|
||||||
|
inline Vec3 operator*(const Vec3& v) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Multiplies this quaternion with the given quaternion.
|
* Multiplies this quaternion with the given quaternion.
|
||||||
*
|
*
|
||||||
|
|
|
@ -35,4 +35,17 @@ inline Quaternion& Quaternion::operator*=(const Quaternion& q)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Vec3 Quaternion::operator*(const Vec3& v) const
|
||||||
|
{
|
||||||
|
Vec3 uv, uuv;
|
||||||
|
Vec3 qvec(x, y, z);
|
||||||
|
Vec3::cross(qvec, v, &uv);
|
||||||
|
Vec3::cross(qvec, uv, &uuv);
|
||||||
|
|
||||||
|
uv *= (2.0f * w);
|
||||||
|
uuv *= 2.0f;
|
||||||
|
|
||||||
|
return v + uv + uuv;
|
||||||
|
}
|
||||||
|
|
||||||
NS_CC_MATH_END
|
NS_CC_MATH_END
|
||||||
|
|
|
@ -419,14 +419,25 @@ public:
|
||||||
*/
|
*/
|
||||||
inline const Vec3 operator/(float s) const;
|
inline const Vec3 operator/(float s) const;
|
||||||
|
|
||||||
/**
|
/** Returns true if the vector's scalar components are all greater
|
||||||
* Determines if this vector is less than the given vector.
|
that the ones of the vector it is compared against.
|
||||||
*
|
|
||||||
* @param v The vector to compare against.
|
|
||||||
*
|
|
||||||
* @return True if this vector is less than the given vector, false otherwise.
|
|
||||||
*/
|
*/
|
||||||
inline bool operator<(const Vec3& v) const;
|
inline bool operator < (const Vec3& rhs) const
|
||||||
|
{
|
||||||
|
if (x < rhs.x && y < rhs.y && z < rhs.z)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns true if the vector's scalar components are all smaller
|
||||||
|
that the ones of the vector it is compared against.
|
||||||
|
*/
|
||||||
|
inline bool operator >(const Vec3& rhs) const
|
||||||
|
{
|
||||||
|
if (x > rhs.x && y > rhs.y && z > rhs.z)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if this vector is equal to the given vector.
|
* Determines if this vector is equal to the given vector.
|
||||||
|
|
|
@ -74,19 +74,6 @@ inline const Vec3 Vec3::operator/(const float s) const
|
||||||
return Vec3(this->x / s, this->y / s, this->z / s);
|
return Vec3(this->x / s, this->y / s, this->z / s);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Vec3::operator<(const Vec3& v) const
|
|
||||||
{
|
|
||||||
if (x == v.x)
|
|
||||||
{
|
|
||||||
if (y == v.y)
|
|
||||||
{
|
|
||||||
return z < v.z;
|
|
||||||
}
|
|
||||||
return y < v.y;
|
|
||||||
}
|
|
||||||
return x < v.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Vec3::operator==(const Vec3& v) const
|
inline bool Vec3::operator==(const Vec3& v) const
|
||||||
{
|
{
|
||||||
return x==v.x && y==v.y && z==v.z;
|
return x==v.x && y==v.y && z==v.z;
|
||||||
|
|
|
@ -159,7 +159,7 @@ GLProgram::~GLProgram()
|
||||||
|
|
||||||
for (auto e : _hashForUniforms)
|
for (auto e : _hashForUniforms)
|
||||||
{
|
{
|
||||||
free(e.second);
|
free(e.second.first);
|
||||||
}
|
}
|
||||||
_hashForUniforms.clear();
|
_hashForUniforms.clear();
|
||||||
}
|
}
|
||||||
|
@ -662,17 +662,22 @@ bool GLProgram::updateUniformLocation(GLint location, const GLvoid* data, unsign
|
||||||
{
|
{
|
||||||
GLvoid* value = malloc(bytes);
|
GLvoid* value = malloc(bytes);
|
||||||
memcpy(value, data, bytes );
|
memcpy(value, data, bytes );
|
||||||
_hashForUniforms.insert(std::make_pair(location, value));
|
_hashForUniforms.insert(std::make_pair(location, std::make_pair(value, bytes)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (memcmp(element->second, data, bytes) == 0)
|
if (memcmp(element->second.first, data, bytes) == 0)
|
||||||
{
|
{
|
||||||
updated = false;
|
updated = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memcpy(element->second, data, bytes);
|
if (element->second.second < bytes){
|
||||||
|
GLvoid* value = realloc(element->second.first, bytes);
|
||||||
|
memcpy(value, data, bytes );
|
||||||
|
_hashForUniforms[location] = std::make_pair(value, bytes);
|
||||||
|
}else
|
||||||
|
memcpy(element->second.first, data, bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -933,7 +938,7 @@ void GLProgram::reset()
|
||||||
|
|
||||||
for (auto e: _hashForUniforms)
|
for (auto e: _hashForUniforms)
|
||||||
{
|
{
|
||||||
free(e.second);
|
free(e.second.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
_hashForUniforms.clear();
|
_hashForUniforms.clear();
|
||||||
|
|
|
@ -357,7 +357,7 @@ protected:
|
||||||
|
|
||||||
std::unordered_map<std::string, Uniform> _userUniforms;
|
std::unordered_map<std::string, Uniform> _userUniforms;
|
||||||
std::unordered_map<std::string, VertexAttrib> _vertexAttribs;
|
std::unordered_map<std::string, VertexAttrib> _vertexAttribs;
|
||||||
std::unordered_map<GLint, GLvoid*> _hashForUniforms;
|
std::unordered_map<GLint, std::pair<GLvoid*, unsigned int>> _hashForUniforms;
|
||||||
//cached director pointer for calling
|
//cached director pointer for calling
|
||||||
Director* _director;
|
Director* _director;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1051,7 +1051,7 @@ void CameraArcBallDemo::onEnter()
|
||||||
{
|
{
|
||||||
_camera=Camera::createPerspective(60, (GLfloat)s.width/s.height, 1, 1000);
|
_camera=Camera::createPerspective(60, (GLfloat)s.width/s.height, 1, 1000);
|
||||||
_camera->setCameraFlag(CameraFlag::USER1);
|
_camera->setCameraFlag(CameraFlag::USER1);
|
||||||
_camera->setPosition3D(Vec3(0, 100, 50));
|
_camera->setPosition3D(Vec3(0, 10, 50));
|
||||||
_camera->lookAt(Vec3(0, 0, 0), Vec3(0, 1, 0));
|
_camera->lookAt(Vec3(0, 0, 0), Vec3(0, 1, 0));
|
||||||
_camera->retain();
|
_camera->retain();
|
||||||
_layer3D->addChild(_camera);
|
_layer3D->addChild(_camera);
|
||||||
|
@ -1175,7 +1175,7 @@ float CameraArcBallDemo::projectToSphere( float r, float x, float y )
|
||||||
void CameraArcBallDemo::updateCameraTransform()
|
void CameraArcBallDemo::updateCameraTransform()
|
||||||
{
|
{
|
||||||
Mat4 trans, rot, center;
|
Mat4 trans, rot, center;
|
||||||
Mat4::createTranslation(Vec3(0.0f, 0.0f, _distanceZ), &trans);
|
Mat4::createTranslation(Vec3(0.0f, 10.0f, _distanceZ), &trans);
|
||||||
Mat4::createRotation(_rotationQuat, &rot);
|
Mat4::createRotation(_rotationQuat, &rot);
|
||||||
Mat4::createTranslation(_center, ¢er);
|
Mat4::createTranslation(_center, ¢er);
|
||||||
Mat4 result = center * rot * trans;
|
Mat4 result = center * rot * trans;
|
||||||
|
|
|
@ -66,7 +66,7 @@ static std::function<Layer*()> createFunctions[] =
|
||||||
CL(Animate3DTest),
|
CL(Animate3DTest),
|
||||||
CL(AttachmentTest),
|
CL(AttachmentTest),
|
||||||
CL(Sprite3DReskinTest),
|
CL(Sprite3DReskinTest),
|
||||||
CL(Sprite3DWithOBBPerfromanceTest),
|
CL(Sprite3DWithOBBPerformanceTest),
|
||||||
CL(Sprite3DMirrorTest),
|
CL(Sprite3DMirrorTest),
|
||||||
CL(QuaternionTest)
|
CL(QuaternionTest)
|
||||||
};
|
};
|
||||||
|
@ -1712,12 +1712,12 @@ void Sprite3DReskinTest::applyCurSkin()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite3DWithOBBPerfromanceTest::Sprite3DWithOBBPerfromanceTest()
|
Sprite3DWithOBBPerformanceTest::Sprite3DWithOBBPerformanceTest()
|
||||||
{
|
{
|
||||||
auto listener = EventListenerTouchAllAtOnce::create();
|
auto listener = EventListenerTouchAllAtOnce::create();
|
||||||
listener->onTouchesBegan = CC_CALLBACK_2(Sprite3DWithOBBPerfromanceTest::onTouchesBegan, this);
|
listener->onTouchesBegan = CC_CALLBACK_2(Sprite3DWithOBBPerformanceTest::onTouchesBegan, this);
|
||||||
listener->onTouchesEnded = CC_CALLBACK_2(Sprite3DWithOBBPerfromanceTest::onTouchesEnded, this);
|
listener->onTouchesEnded = CC_CALLBACK_2(Sprite3DWithOBBPerformanceTest::onTouchesEnded, this);
|
||||||
listener->onTouchesMoved = CC_CALLBACK_2(Sprite3DWithOBBPerfromanceTest::onTouchesMoved, this);
|
listener->onTouchesMoved = CC_CALLBACK_2(Sprite3DWithOBBPerformanceTest::onTouchesMoved, this);
|
||||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||||
auto s = Director::getInstance()->getWinSize();
|
auto s = Director::getInstance()->getWinSize();
|
||||||
initDrawBox();
|
initDrawBox();
|
||||||
|
@ -1725,9 +1725,9 @@ Sprite3DWithOBBPerfromanceTest::Sprite3DWithOBBPerfromanceTest()
|
||||||
addNewSpriteWithCoords(Vec2(s.width/2, s.height/2));
|
addNewSpriteWithCoords(Vec2(s.width/2, s.height/2));
|
||||||
MenuItemFont::setFontName("fonts/arial.ttf");
|
MenuItemFont::setFontName("fonts/arial.ttf");
|
||||||
MenuItemFont::setFontSize(65);
|
MenuItemFont::setFontSize(65);
|
||||||
auto decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(Sprite3DWithOBBPerfromanceTest::delOBBCallback, this));
|
auto decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(Sprite3DWithOBBPerformanceTest::delOBBCallback, this));
|
||||||
decrease->setColor(Color3B(0,200,20));
|
decrease->setColor(Color3B(0,200,20));
|
||||||
auto increase = MenuItemFont::create(" + ", CC_CALLBACK_1(Sprite3DWithOBBPerfromanceTest::addOBBCallback, this));
|
auto increase = MenuItemFont::create(" + ", CC_CALLBACK_1(Sprite3DWithOBBPerformanceTest::addOBBCallback, this));
|
||||||
increase->setColor(Color3B(0,200,20));
|
increase->setColor(Color3B(0,200,20));
|
||||||
|
|
||||||
auto menu = Menu::create(decrease, increase, nullptr);
|
auto menu = Menu::create(decrease, increase, nullptr);
|
||||||
|
@ -1744,15 +1744,15 @@ Sprite3DWithOBBPerfromanceTest::Sprite3DWithOBBPerfromanceTest()
|
||||||
addOBBCallback(nullptr);
|
addOBBCallback(nullptr);
|
||||||
scheduleUpdate();
|
scheduleUpdate();
|
||||||
}
|
}
|
||||||
std::string Sprite3DWithOBBPerfromanceTest::title() const
|
std::string Sprite3DWithOBBPerformanceTest::title() const
|
||||||
{
|
{
|
||||||
return "OBB Collison Perfromance Test";
|
return "OBB Collison Performance Test";
|
||||||
}
|
}
|
||||||
std::string Sprite3DWithOBBPerfromanceTest::subtitle() const
|
std::string Sprite3DWithOBBPerformanceTest::subtitle() const
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
void Sprite3DWithOBBPerfromanceTest::addNewOBBWithCoords(Vec2 p)
|
void Sprite3DWithOBBPerformanceTest::addNewOBBWithCoords(Vec2 p)
|
||||||
{
|
{
|
||||||
Vec3 extents = Vec3(10, 10, 10);
|
Vec3 extents = Vec3(10, 10, 10);
|
||||||
AABB aabb(-extents, extents);
|
AABB aabb(-extents, extents);
|
||||||
|
@ -1761,7 +1761,7 @@ void Sprite3DWithOBBPerfromanceTest::addNewOBBWithCoords(Vec2 p)
|
||||||
_obb.push_back(obb);
|
_obb.push_back(obb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite3DWithOBBPerfromanceTest::onTouchesBegan(const std::vector<Touch*>& touches, Event* event)
|
void Sprite3DWithOBBPerformanceTest::onTouchesBegan(const std::vector<Touch*>& touches, Event* event)
|
||||||
{
|
{
|
||||||
for (const auto& touch: touches)
|
for (const auto& touch: touches)
|
||||||
{
|
{
|
||||||
|
@ -1784,12 +1784,12 @@ void Sprite3DWithOBBPerfromanceTest::onTouchesBegan(const std::vector<Touch*>& t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite3DWithOBBPerfromanceTest::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
void Sprite3DWithOBBPerformanceTest::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite3DWithOBBPerfromanceTest::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)
|
void Sprite3DWithOBBPerformanceTest::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)
|
||||||
{
|
{
|
||||||
for (const auto& touch: touches)
|
for (const auto& touch: touches)
|
||||||
{
|
{
|
||||||
|
@ -1804,7 +1804,7 @@ void Sprite3DWithOBBPerfromanceTest::onTouchesMoved(const std::vector<Touch*>& t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite3DWithOBBPerfromanceTest::update(float dt)
|
void Sprite3DWithOBBPerformanceTest::update(float dt)
|
||||||
{
|
{
|
||||||
char szText[16];
|
char szText[16];
|
||||||
sprintf(szText,"%lu cubes",_obb.size());
|
sprintf(szText,"%lu cubes",_obb.size());
|
||||||
|
@ -1843,13 +1843,13 @@ void Sprite3DWithOBBPerfromanceTest::update(float dt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite3DWithOBBPerfromanceTest::initDrawBox()
|
void Sprite3DWithOBBPerformanceTest::initDrawBox()
|
||||||
{
|
{
|
||||||
_drawOBB = DrawNode3D::create();
|
_drawOBB = DrawNode3D::create();
|
||||||
addChild(_drawOBB);
|
addChild(_drawOBB);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite3DWithOBBPerfromanceTest::addNewSpriteWithCoords(Vec2 p)
|
void Sprite3DWithOBBPerformanceTest::addNewSpriteWithCoords(Vec2 p)
|
||||||
{
|
{
|
||||||
std::string fileName = "Sprite3DTest/tortoise.c3b";
|
std::string fileName = "Sprite3DTest/tortoise.c3b";
|
||||||
auto sprite = Sprite3D::create(fileName);
|
auto sprite = Sprite3D::create(fileName);
|
||||||
|
@ -1867,7 +1867,7 @@ void Sprite3DWithOBBPerfromanceTest::addNewSpriteWithCoords(Vec2 p)
|
||||||
|
|
||||||
_moveAction = MoveTo::create(4.f, Vec2(s.width / 5.f, s.height / 2.f));
|
_moveAction = MoveTo::create(4.f, Vec2(s.width / 5.f, s.height / 2.f));
|
||||||
_moveAction->retain();
|
_moveAction->retain();
|
||||||
auto seq = Sequence::create(_moveAction, CallFunc::create(CC_CALLBACK_0(Sprite3DWithOBBPerfromanceTest::reachEndCallBack, this)), nullptr);
|
auto seq = Sequence::create(_moveAction, CallFunc::create(CC_CALLBACK_0(Sprite3DWithOBBPerformanceTest::reachEndCallBack, this)), nullptr);
|
||||||
seq->setTag(100);
|
seq->setTag(100);
|
||||||
sprite->runAction(seq);
|
sprite->runAction(seq);
|
||||||
|
|
||||||
|
@ -1878,7 +1878,7 @@ void Sprite3DWithOBBPerfromanceTest::addNewSpriteWithCoords(Vec2 p)
|
||||||
addChild(_drawDebug);
|
addChild(_drawDebug);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite3DWithOBBPerfromanceTest::reachEndCallBack()
|
void Sprite3DWithOBBPerformanceTest::reachEndCallBack()
|
||||||
{
|
{
|
||||||
_sprite->stopActionByTag(100);
|
_sprite->stopActionByTag(100);
|
||||||
auto inverse = (MoveTo*)_moveAction->reverse();
|
auto inverse = (MoveTo*)_moveAction->reverse();
|
||||||
|
@ -1886,17 +1886,17 @@ void Sprite3DWithOBBPerfromanceTest::reachEndCallBack()
|
||||||
_moveAction->release();
|
_moveAction->release();
|
||||||
_moveAction = inverse;
|
_moveAction = inverse;
|
||||||
auto rot = RotateBy::create(1.0f, Vec3(0.f, 180.f, 0.f));
|
auto rot = RotateBy::create(1.0f, Vec3(0.f, 180.f, 0.f));
|
||||||
auto seq = Sequence::create(rot, _moveAction, CallFunc::create(CC_CALLBACK_0(Sprite3DWithOBBPerfromanceTest::reachEndCallBack, this)), nullptr);
|
auto seq = Sequence::create(rot, _moveAction, CallFunc::create(CC_CALLBACK_0(Sprite3DWithOBBPerformanceTest::reachEndCallBack, this)), nullptr);
|
||||||
seq->setTag(100);
|
seq->setTag(100);
|
||||||
_sprite->runAction(seq);
|
_sprite->runAction(seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite3DWithOBBPerfromanceTest::addOBBCallback(Ref* sender)
|
void Sprite3DWithOBBPerformanceTest::addOBBCallback(Ref* sender)
|
||||||
{
|
{
|
||||||
addOBBWithCount(10);
|
addOBBWithCount(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite3DWithOBBPerfromanceTest::addOBBWithCount(float value)
|
void Sprite3DWithOBBPerformanceTest::addOBBWithCount(float value)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < value; i++)
|
for(int i = 0; i < value; i++)
|
||||||
{
|
{
|
||||||
|
@ -1909,12 +1909,12 @@ void Sprite3DWithOBBPerfromanceTest::addOBBWithCount(float value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite3DWithOBBPerfromanceTest::delOBBCallback(Ref* sender)
|
void Sprite3DWithOBBPerformanceTest::delOBBCallback(Ref* sender)
|
||||||
{
|
{
|
||||||
delOBBWithCount(10);
|
delOBBWithCount(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite3DWithOBBPerfromanceTest::delOBBWithCount(float value)
|
void Sprite3DWithOBBPerformanceTest::delOBBWithCount(float value)
|
||||||
{
|
{
|
||||||
if(_obb.size() >= 10)
|
if(_obb.size() >= 10)
|
||||||
{
|
{
|
||||||
|
@ -1924,7 +1924,7 @@ void Sprite3DWithOBBPerfromanceTest::delOBBWithCount(float value)
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void Sprite3DWithOBBPerfromanceTest::unproject(const Mat4& viewProjection, const Size* viewport, Vec3* src, Vec3* dst)
|
void Sprite3DWithOBBPerformanceTest::unproject(const Mat4& viewProjection, const Size* viewport, Vec3* src, Vec3* dst)
|
||||||
{
|
{
|
||||||
assert(dst);
|
assert(dst);
|
||||||
|
|
||||||
|
@ -1947,7 +1947,7 @@ void Sprite3DWithOBBPerfromanceTest::unproject(const Mat4& viewProjection, const
|
||||||
dst->set(screen.x, screen.y, screen.z);
|
dst->set(screen.x, screen.y, screen.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite3DWithOBBPerfromanceTest::calculateRayByLocationInView(Ray* ray, const Vec2& location)
|
void Sprite3DWithOBBPerformanceTest::calculateRayByLocationInView(Ray* ray, const Vec2& location)
|
||||||
{
|
{
|
||||||
auto dir = Director::getInstance();
|
auto dir = Director::getInstance();
|
||||||
auto view = dir->getWinSize();
|
auto view = dir->getWinSize();
|
||||||
|
|
|
@ -378,11 +378,11 @@ protected:
|
||||||
int _curSkin[(int)SkinType::MAX_TYPE]; //current skin index
|
int _curSkin[(int)SkinType::MAX_TYPE]; //current skin index
|
||||||
cocos2d::Sprite3D* _sprite;
|
cocos2d::Sprite3D* _sprite;
|
||||||
};
|
};
|
||||||
class Sprite3DWithOBBPerfromanceTest : public Sprite3DTestDemo
|
class Sprite3DWithOBBPerformanceTest : public Sprite3DTestDemo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CREATE_FUNC(Sprite3DWithOBBPerfromanceTest);
|
CREATE_FUNC(Sprite3DWithOBBPerformanceTest);
|
||||||
Sprite3DWithOBBPerfromanceTest();
|
Sprite3DWithOBBPerformanceTest();
|
||||||
virtual std::string title() const override;
|
virtual std::string title() const override;
|
||||||
virtual std::string subtitle() const override;
|
virtual std::string subtitle() const override;
|
||||||
virtual void update(float dt) override;
|
virtual void update(float dt) override;
|
||||||
|
|
Loading…
Reference in New Issue