d3drm: Implement d3drm_frame3_Transform().

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jeff Smith 2019-06-20 02:29:55 +04:30 committed by Alexandre Julliard
parent c241a9c054
commit 328d002d84
2 changed files with 85 additions and 31 deletions

View File

@ -155,6 +155,17 @@ static void d3drm_matrix_set_rotation(struct d3drm_matrix *matrix, D3DVECTOR *ax
matrix->_44 = 1.0f;
}
static void d3drm_vector_transform_affine(D3DVECTOR *dst, const D3DVECTOR *v, const struct d3drm_matrix *m)
{
D3DVECTOR tmp;
tmp.u1.x = v->u1.x * m->_11 + v->u2.y * m->_21 + v->u3.z * m->_31 + m->_41;
tmp.u2.y = v->u1.x * m->_12 + v->u2.y * m->_22 + v->u3.z * m->_32 + m->_42;
tmp.u3.z = v->u1.x * m->_13 + v->u2.y * m->_23 + v->u3.z * m->_33 + m->_43;
*dst = tmp;
}
static HRESULT WINAPI d3drm_frame_array_QueryInterface(IDirect3DRMFrameArray *iface, REFIID riid, void **out)
{
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
@ -2592,23 +2603,35 @@ static HRESULT WINAPI d3drm_frame1_SetZbufferMode(IDirect3DRMFrame *iface, D3DRM
static HRESULT WINAPI d3drm_frame3_Transform(IDirect3DRMFrame3 *iface, D3DVECTOR *d, D3DVECTOR *s)
{
FIXME("iface %p, d %p, s %p stub!\n", iface, d, s);
struct d3drm_frame *frame = impl_from_IDirect3DRMFrame3(iface);
return E_NOTIMPL;
TRACE("iface %p, d %p, s %p.\n", iface, d, s);
d3drm_vector_transform_affine(d, s, &frame->transform);
while ((frame = frame->parent))
{
d3drm_vector_transform_affine(d, d, &frame->transform);
}
return D3DRM_OK;
}
static HRESULT WINAPI d3drm_frame2_Transform(IDirect3DRMFrame2 *iface, D3DVECTOR *d, D3DVECTOR *s)
{
FIXME("iface %p, d %p, s %p stub!\n", iface, d, s);
struct d3drm_frame *frame = impl_from_IDirect3DRMFrame2(iface);
return E_NOTIMPL;
TRACE("iface %p, d %p, s %p.\n", iface, d, s);
return d3drm_frame3_Transform(&frame->IDirect3DRMFrame3_iface, d, s);
}
static HRESULT WINAPI d3drm_frame1_Transform(IDirect3DRMFrame *iface, D3DVECTOR *d, D3DVECTOR *s)
{
FIXME("iface %p, d %p, s %p stub!\n", iface, d, s);
struct d3drm_frame *frame = impl_from_IDirect3DRMFrame(iface);
return E_NOTIMPL;
TRACE("iface %p, d %p, s %p.\n", iface, d, s);
return d3drm_frame3_Transform(&frame->IDirect3DRMFrame3_iface, d, s);
}
static HRESULT WINAPI d3drm_frame2_AddMoveCallback2(IDirect3DRMFrame2 *iface,

View File

@ -86,21 +86,21 @@ static void expect_matrix_(unsigned int line, D3DRMMATRIX4D m,
m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44);
}
#define check_vector(a, b, c, d, e) check_vector_(__LINE__, a, b, c, d, e)
static void check_vector_(unsigned int line, const D3DVECTOR *v, float x, float y, float z, unsigned int ulps)
#define expect_vector(v, x, y, z, u) expect_vector_(__LINE__, v, x, y, z, u)
static void expect_vector_(unsigned int line, const D3DVECTOR *v, float x, float y, float z, unsigned int ulps)
{
BOOL ret = compare_float(U1(v)->x, x, ulps)
&& compare_float(U2(v)->y, y, ulps)
&& compare_float(U3(v)->z, z, ulps);
BOOL equal = compare_float(U1(*v).x, x, ulps)
&& compare_float(U2(*v).y, y, ulps)
&& compare_float(U3(*v).z, z, ulps);
ok_(__FILE__, line)(ret, "Got unexpected vector {%.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e}.\n",
U1(v)->x, U2(v)->y, U3(v)->z, x, y, z);
ok_(__FILE__, line)(equal, "Got unexpected vector {%.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e}.\n",
U1(*v).x, U2(*v).y, U3(*v).z, x, y, z);
}
#define vector_eq(a, b) vector_eq_(__LINE__, a, b)
static void vector_eq_(unsigned int line, const D3DVECTOR *left, const D3DVECTOR *right)
{
check_vector_(line, left, U1(right)->x, U2(right)->y, U3(right)->z, 0);
expect_vector_(line, left, U1(*right).x, U2(*right).y, U3(*right).z, 0);
}
static D3DRMMATRIX4D identity = {
@ -125,6 +125,13 @@ static void frame_set_transform(IDirect3DRMFrame *frame,
IDirect3DRMFrame_AddTransform(frame, D3DRMCOMBINE_REPLACE, matrix);
}
static void set_vector(D3DVECTOR *v, float x, float y, float z)
{
U1(*v).x = x;
U2(*v).y = y;
U3(*v).z = z;
}
static void matrix_sanitise(D3DRMMATRIX4D m)
{
unsigned int i, j;
@ -515,10 +522,10 @@ static void test_MeshBuilder(void)
/* Check that Load method generated default normals */
hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, NULL, NULL, &val2, n, NULL, NULL);
ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
check_vector(&n[0], 0.577350f, 0.577350f, 0.577350f, 32);
check_vector(&n[1], -0.229416f, 0.688247f, 0.688247f, 32);
check_vector(&n[2], -0.229416f, 0.688247f, 0.688247f, 32);
check_vector(&n[3], -0.577350f, 0.577350f, 0.577350f, 32);
expect_vector(&n[0], 0.577350f, 0.577350f, 0.577350f, 32);
expect_vector(&n[1], -0.229416f, 0.688247f, 0.688247f, 32);
expect_vector(&n[2], -0.229416f, 0.688247f, 0.688247f, 32);
expect_vector(&n[3], -0.577350f, 0.577350f, 0.577350f, 32);
/* Check that Load method generated default texture coordinates (0.0f, 0.0f) for each vertex */
valu = 1.23f;
@ -614,12 +621,12 @@ static void test_MeshBuilder(void)
ok(val1 == 3, "Wrong number of vertices %d (must be 3)\n", val1);
ok(val2 == 3, "Wrong number of normals %d (must be 3)\n", val2);
ok(val3 == 8, "Wrong number of face data bytes %d (must be 8)\n", val3);
check_vector(&v[0], 0.1f, 0.2f, 0.3f, 32);
check_vector(&v[1], 0.4f, 0.5f, 0.6f, 32);
check_vector(&v[2], 0.7f, 0.8f, 0.9f, 32);
check_vector(&n[0], 1.1f, 1.2f, 1.3f, 32);
check_vector(&n[1], 1.4f, 1.5f, 1.6f, 32);
check_vector(&n[2], 1.7f, 1.8f, 1.9f, 32);
expect_vector(&v[0], 0.1f, 0.2f, 0.3f, 32);
expect_vector(&v[1], 0.4f, 0.5f, 0.6f, 32);
expect_vector(&v[2], 0.7f, 0.8f, 0.9f, 32);
expect_vector(&n[0], 1.1f, 1.2f, 1.3f, 32);
expect_vector(&n[1], 1.4f, 1.5f, 1.6f, 32);
expect_vector(&n[2], 1.7f, 1.8f, 1.9f, 32);
ok(f[0] == 3 , "Wrong component f[0] = %d (expected 3)\n", f[0]);
ok(f[1] == 0 , "Wrong component f[1] = %d (expected 0)\n", f[1]);
ok(f[2] == 0 , "Wrong component f[2] = %d (expected 0)\n", f[2]);
@ -683,13 +690,13 @@ static void test_MeshBuilder(void)
ok(val2 == 3, "Wrong number of normals %d (must be 3)\n", val2);
ok(val1 == 3, "Wrong number of vertices %d (must be 3)\n", val1);
check_vector(&v[0], 0.1f * 2, 0.2f * 3, 0.3f * 4, 32);
check_vector(&v[1], 0.4f * 2, 0.5f * 3, 0.6f * 4, 32);
check_vector(&v[2], 0.7f * 2, 0.8f * 3, 0.9f * 4, 32);
expect_vector(&v[0], 0.1f * 2, 0.2f * 3, 0.3f * 4, 32);
expect_vector(&v[1], 0.4f * 2, 0.5f * 3, 0.6f * 4, 32);
expect_vector(&v[2], 0.7f * 2, 0.8f * 3, 0.9f * 4, 32);
/* Normals are not affected by Scale */
check_vector(&n[0], 1.1f, 1.2f, 1.3f, 32);
check_vector(&n[1], 1.4f, 1.5f, 1.6f, 32);
check_vector(&n[2], 1.7f, 1.8f, 1.9f, 32);
expect_vector(&n[0], 1.1f, 1.2f, 1.3f, 32);
expect_vector(&n[1], 1.4f, 1.5f, 1.6f, 32);
expect_vector(&n[2], 1.7f, 1.8f, 1.9f, 32);
IDirect3DRMMeshBuilder_Release(pMeshBuilder);
@ -2768,9 +2775,10 @@ cleanup:
static void test_frame_transform(void)
{
IDirect3DRMFrame *frame, *subframe;
D3DRMMATRIX4D matrix, add_matrix;
IDirect3DRMFrame *frame;
IDirect3DRM *d3drm;
D3DVECTOR v1, v2;
HRESULT hr;
hr = Direct3DRMCreate(&d3drm);
@ -3000,6 +3008,29 @@ static void test_frame_transform(void)
0.0f, -1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 1);
frame_set_transform(frame,
2.0f, 0.0f, 0.0f, 0.0f,
0.0f, 4.0f, 0.0f, 0.0f,
0.0f, 0.0f, 8.0f, 0.0f,
64.0f, 64.0f, 64.0f, 1.0f);
hr = IDirect3DRM_CreateFrame(d3drm, frame, &subframe);
ok(hr == D3DRM_OK, "Got unexpected hr %#x.\n", hr);
frame_set_transform(subframe,
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
11.0f, 11.0f, 11.0f, 1.0f);
set_vector(&v1, 3.0f, 5.0f, 7.0f);
hr = IDirect3DRMFrame_Transform(frame, &v2, &v1);
ok(hr == D3DRM_OK, "Got unexpected hr %#x.\n", hr);
expect_vector(&v2, 70.0f, 84.0f, 120.0f, 1);
hr = IDirect3DRMFrame_Transform(subframe, &v2, &v1);
ok(hr == D3DRM_OK, "Got unexpected hr %#x.\n", hr);
expect_vector(&v2, 92.0f, 128.0f, 208.0f, 1);
IDirect3DRMFrame_Release(subframe);
IDirect3DRMFrame_Release(frame);
IDirect3DRM_Release(d3drm);
}