mirror of https://github.com/axmolengine/axmol.git
modify Camera::project
This commit is contained in:
parent
23df00b0b9
commit
6d92b7adc9
|
@ -234,21 +234,17 @@ bool Camera::initOrthographic(float zoomX, float zoomY, float nearPlane, float f
|
|||
return true;
|
||||
}
|
||||
|
||||
void Camera::project(const Rect& viewport, const Vec3& position, Vec2* out) const
|
||||
void Camera::project(const Size& viewport, Vec3* src, Vec2* dst) const
|
||||
{
|
||||
|
||||
// Transform the point to clip-space.
|
||||
Vec4 clipPos;
|
||||
getViewProjectionMatrix().transformVector(Vec4(position.x, position.y, position.z, 1.0f), &clipPos);
|
||||
getViewProjectionMatrix().transformVector(Vec4(src->x, src->y, src->z, 1.0f), &clipPos);
|
||||
|
||||
// Compute normalized device coordinates.
|
||||
GP_ASSERT(clipPos.w != 0.0f);
|
||||
float ndcX = clipPos.x / clipPos.w;
|
||||
float ndcY = clipPos.y / clipPos.w;
|
||||
|
||||
// Compute screen coordinates by applying our viewport transformation.
|
||||
out->x = viewport.origin.x + (ndcX + 1.0f) * 0.5f * viewport.size.width;
|
||||
out->y = viewport.origin.y + (1.0f - (ndcY + 1.0f) * 0.5f) * viewport.size.height;
|
||||
dst->x = (ndcX + 1.0f) * 0.5f * viewport.width;
|
||||
dst->y = (1.0f - (ndcY + 1.0f) * 0.5f) * viewport.height;
|
||||
}
|
||||
|
||||
void Camera::unproject(const Size& viewport, Vec3* src, Vec3* dst) const
|
||||
|
|
|
@ -131,10 +131,21 @@ public:
|
|||
/**get view projection matrix*/
|
||||
const Mat4& getViewProjectionMatrix() const;
|
||||
|
||||
void project(const Rect& viewport, const Vec3& position, Vec2* out) const;
|
||||
/**
|
||||
* convert the specified point of viewport from world-space coordinates into the screen-space coordinates.
|
||||
*
|
||||
* @param viewport The viewport size to use.
|
||||
* @param src The world-space position.
|
||||
* @param dst The screen-space position.
|
||||
*/
|
||||
void project(const Size& viewport, Vec3* src, Vec2* dst) const;
|
||||
|
||||
/**
|
||||
* Convert the specified point of viewport from screenspace coordinate into the worldspace coordinate.
|
||||
* Convert the specified point of viewport from screen-space coordinate into the world-space coordinate.
|
||||
*
|
||||
* @param viewport The viewport size to use.
|
||||
* @param src The screen-space position.
|
||||
* @param dst The world-space position.
|
||||
*/
|
||||
void unproject(const Size& viewport, Vec3* src, Vec3* dst) const;
|
||||
|
||||
|
|
Loading…
Reference in New Issue