2013-06-24 20:58:35 +02:00
|
|
|
// Copyright (c) 2013- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#include "TransformUnit.h"
|
|
|
|
#include "../GPUState.h"
|
|
|
|
|
|
|
|
WorldCoords TransformUnit::ModelToWorld(const ModelCoords& coords)
|
|
|
|
{
|
|
|
|
Mat3x3<float> world_matrix(gstate.worldMatrix);
|
|
|
|
return WorldCoords(world_matrix * coords) + Vec3<float>(gstate.worldMatrix[9], gstate.worldMatrix[10], gstate.worldMatrix[11]);
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewCoords TransformUnit::WorldToView(const WorldCoords& coords)
|
|
|
|
{
|
|
|
|
Mat3x3<float> view_matrix(gstate.viewMatrix);
|
|
|
|
return ViewCoords(view_matrix * coords) + Vec3<float>(gstate.viewMatrix[9], gstate.viewMatrix[10], gstate.viewMatrix[11]);
|
|
|
|
}
|
|
|
|
|
|
|
|
ClipCoords TransformUnit::ViewToClip(const ViewCoords& coords)
|
|
|
|
{
|
2013-06-24 21:27:40 +02:00
|
|
|
Vec4<float> coords4(coords.x, coords.y, coords.z, 1.0f);
|
|
|
|
Mat4x4<float> projection_matrix(gstate.projMatrix);
|
|
|
|
return ClipCoords(projection_matrix * coords4);
|
2013-06-24 20:58:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ScreenCoords TransformUnit::ClipToScreen(const ClipCoords& coords)
|
|
|
|
{
|
|
|
|
ScreenCoords ret;
|
2013-06-25 11:53:45 +02:00
|
|
|
float vpx1 = getFloat24(gstate.viewportx1);
|
|
|
|
float vpx2 = getFloat24(gstate.viewportx2);
|
|
|
|
float vpy1 = getFloat24(gstate.viewporty1);
|
|
|
|
float vpy2 = getFloat24(gstate.viewporty2);
|
|
|
|
float vpz1 = getFloat24(gstate.viewportz1);
|
|
|
|
float vpz2 = getFloat24(gstate.viewportz2);
|
2013-06-24 21:27:40 +02:00
|
|
|
// TODO: Check for invalid parameters (x2 < x1, etc)
|
2013-06-25 15:27:24 +02:00
|
|
|
ret.x = (coords.x * vpx1 / coords.w + vpx2) / 4095.9375 * 0xFFFF;
|
|
|
|
ret.y = (coords.y * vpy1 / coords.w + vpy2) / 4096.9375 * 0xFFFF;
|
|
|
|
ret.z = (coords.z * vpz1 / coords.w + vpz2) / 4096.9375 * 0xFFFF;
|
2013-06-24 20:58:35 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawingCoords TransformUnit::ScreenToDrawing(const ScreenCoords& coords)
|
|
|
|
{
|
|
|
|
DrawingCoords ret;
|
2013-06-25 15:27:24 +02:00
|
|
|
// TODO: What to do when offset > coord?
|
|
|
|
// TODO: Mask can be re-enabled now, I guess.
|
2013-06-25 15:36:45 +02:00
|
|
|
ret.x = (((u32)coords.x - (gstate.offsetx&0xffff))/16) & 0x3ff;
|
|
|
|
ret.y = (((u32)coords.y - (gstate.offsety&0xffff))/16) & 0x3ff;
|
2013-06-24 20:58:35 +02:00
|
|
|
return ret;
|
|
|
|
}
|