Skip to content

Commit cbfff96

Browse files
committed
Stat making video/model1.cpp use glm as necessary, nw
1 parent 9c4bbdb commit cbfff96

File tree

2 files changed

+40
-81
lines changed

2 files changed

+40
-81
lines changed

src/mame/includes/model1.h

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// copyright-holders:Olivier Galibert
33
#include <functional>
44

5+
#include <glm/glm/vec3.hpp>
6+
57
#include "audio/dsbz80.h"
68
#include "audio/segam1audio.h"
79
#include "cpu/v60/v60.h"
@@ -125,36 +127,6 @@ class model1_state : public driver_device
125127
int col;
126128
};
127129

128-
// TOOD: Replace with glm::vec3
129-
class vector_t
130-
{
131-
public:
132-
vector_t()
133-
{
134-
memset(v, 0, sizeof(float) * 3);
135-
}
136-
vector_t(float x, float y, float z)
137-
{
138-
set_x(x);
139-
set_y(y);
140-
set_z(z);
141-
}
142-
143-
void normalize();
144-
145-
static float dot(const vector_t& a, const vector_t& b);
146-
147-
float x() { return v[0]; }
148-
float y() { return v[1]; }
149-
float z() { return v[2]; }
150-
void set_x(float x) { v[0] = x; }
151-
void set_y(float y) { v[1] = y; }
152-
void set_z(float z) { v[2] = z; }
153-
154-
private:
155-
float v[3];
156-
};
157-
158130
struct lightparam_t
159131
{
160132
float a;
@@ -169,18 +141,18 @@ class model1_state : public driver_device
169141
view_t() { }
170142

171143
void init_translation_matrix();
172-
144+
173145
void set_viewport(float xcenter, float ycenter, float xl, float xr, float yb, float yt);
174146
void set_lightparam(int index, float diffuse, float ambient, float specular, int power);
175147
void set_zoom(float x, float y);
176148
void set_light_direction(float x, float y, float z);
177149
void set_translation_matrix(float* mat);
178150
void set_view_translation(float x, float y);
179-
151+
180152
void project_point(point_t *p) const;
181153
void project_point_direct(point_t *p) const;
182-
183-
void transform_vector(vector_t *p) const;
154+
155+
void transform_vector(glm::vec3& p) const;
184156
void transform_point(point_t *p) const;
185157

186158
void recompute_frustum();
@@ -190,7 +162,7 @@ class model1_state : public driver_device
190162
float a_bottom, a_top, a_left, a_right;
191163
float vxx, vyy, vzz, ayy, ayyc, ayys;
192164
float translation[12];
193-
vector_t light;
165+
glm::vec3 light;
194166
lightparam_t lightparams[32];
195167
};
196168

@@ -467,7 +439,7 @@ class model1_state : public driver_device
467439

468440
static float min4f(float a, float b, float c, float d);
469441
static float max4f(float a, float b, float c, float d);
470-
static float compute_specular(vector_t *normal, vector_t *light, float diffuse,int lmode);
442+
static float compute_specular(glm::vec3& normal, glm::vec3& light, float diffuse,int lmode);
471443

472444
void push_object(UINT32 tex_adr, UINT32 poly_adr, UINT32 size);
473445
UINT16* push_direct(UINT16 *list);

src/mame/video/model1.cpp

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// license:BSD-3-Clause
22
// copyright-holders:Olivier Galibert
3+
4+
#include <glm/glm/geometric.hpp>
5+
36
#include "emu.h"
47
#include "cpu/mb86233/mb86233.h"
58
#include "includes/model1.h"
@@ -32,36 +35,23 @@ float model1_state::readf(const UINT16 *adr) const
3235
void model1_state::view_t::transform_point(point_t *p) const
3336
{
3437
point_t q = *p;
35-
float xx, zz;
36-
xx = translation[0] * q.x + translation[3] * q.y + translation[6] * q.z + translation[ 9] + vxx;
37-
p->y = translation[1] * q.x + translation[4] * q.y + translation[7] * q.z + translation[10] + vyy;
38-
zz = translation[2] * q.x + translation[5] * q.y + translation[8] * q.z + translation[11] + vzz;
38+
float xx = translation[0] * q.x + translation[3] * q.y + translation[6] * q.z + translation[ 9] + vxx;
39+
p->y = translation[1] * q.x + translation[4] * q.y + translation[7] * q.z + translation[10] + vyy;
40+
float zz = translation[2] * q.x + translation[5] * q.y + translation[8] * q.z + translation[11] + vzz;
3941
p->x = ayyc * xx - ayys * zz;
4042
p->z = ayys * xx + ayyc * zz;
4143
}
4244

43-
void model1_state::view_t::transform_vector(vector_t *p) const
45+
void model1_state::view_t::transform_vector(glm::vec3& p) const
4446
{
45-
vector_t q = *p;
46-
p->set_x(translation[0] * q.x() + translation[3] * q.y() + translation[6] * q.z());
47-
p->set_x(translation[1] * q.x() + translation[4] * q.y() + translation[7] * q.z());
48-
p->set_x(translation[2] * q.x() + translation[5] * q.y() + translation[8] * q.z());
49-
}
50-
51-
void model1_state::vector_t::normalize()
52-
{
53-
float norm = sqrt(dot(*this, *this));
54-
if (norm)
55-
{
56-
v[0] /= norm;
57-
v[1] /= norm;
58-
v[2] /= norm;
59-
}
60-
}
61-
62-
float model1_state::vector_t::dot(const vector_t& a, const vector_t& b)
63-
{
64-
return a.v[0] * b.v[0] + a.v[1] * b.v[1] + a.v[2] * b.v[2];
47+
glm::vec3 q(p);
48+
glm::vec3 row1(translation[0], translation[3], translation[6]);
49+
glm::vec3 row2(translation[1], translation[4], translation[7]);
50+
glm::vec3 row3(translation[2], translation[5], translation[8]);
51+
p = glm::vec3(glm::dot(q, row1), glm::dot(q, row2), glm::dot(q, row3));
52+
//p->set_x(translation[0] * q.x() + translation[3] * q.y() + translation[6] * q.z());
53+
//p->set_y(translation[1] * q.x() + translation[4] * q.y() + translation[7] * q.z());
54+
//p->set_z(translation[2] * q.x() + translation[5] * q.y() + translation[8] * q.z());
6555
}
6656

6757
void model1_state::cross_product(point_t* o, const point_t* p, const point_t* q) const
@@ -735,14 +725,14 @@ float model1_state::max4f(float a, float b, float c, float d)
735725
#ifdef UNUSED_DEFINITION
736726
static const UINT8 num_of_times[]={1,1,1,1,2,2,2,3};
737727
#endif
738-
float model1_state::compute_specular(vector_t *normal, vector_t *light, float diffuse,int lmode)
728+
float model1_state::compute_specular(glm::vec3& normal, glm::vec3& light, float diffuse, int lmode)
739729
{
740730
#if 0
741-
int p = view->lightparams[lmode].p & 7;
742-
float sv = view->lightparams[lmode].s;
731+
int p = m_view->lightparams[lmode].p & 7;
732+
float sv = m_view->lightparams[lmode].s;
743733

744734
//This is how it should be according to model2 geo program, but doesn't work fine
745-
float s = 2 * (diffuse * normal->z - light->z);
735+
float s = 2 * (diffuse * normal.z - light.z);
746736
for (int i = 0; i < num_of_times[p]; i++)
747737
{
748738
s *= s;
@@ -769,7 +759,7 @@ void model1_state::push_object(UINT32 tex_adr, UINT32 poly_adr, UINT32 size) {
769759
#if 0
770760
int dump;
771761
#endif
772-
762+
773763
float *poly_data;
774764
if (poly_adr & 0x800000)
775765
poly_data = (float *)m_poly_ram.get();
@@ -814,7 +804,7 @@ void model1_state::push_object(UINT32 tex_adr, UINT32 poly_adr, UINT32 size) {
814804
old_p1->z = poly_data[poly_adr + 5];
815805
m_view->transform_point(old_p0);
816806
m_view->transform_point(old_p1);
817-
807+
818808
if (old_p0->z > 0)
819809
{
820810
m_view->project_point(old_p0);
@@ -823,7 +813,7 @@ void model1_state::push_object(UINT32 tex_adr, UINT32 poly_adr, UINT32 size) {
823813
{
824814
old_p0->s.x = old_p0->s.y = 0;
825815
}
826-
816+
827817
if (old_p1->z > 0)
828818
{
829819
m_view->project_point(old_p1);
@@ -859,7 +849,7 @@ void model1_state::push_object(UINT32 tex_adr, UINT32 poly_adr, UINT32 size) {
859849
point_t *p0 = m_pointpt++;
860850
point_t *p1 = m_pointpt++;
861851

862-
vector_t vn(poly_data[poly_adr + 1], poly_data[poly_adr + 2], poly_data[poly_adr + 3]);
852+
glm::vec3 vn(poly_data[poly_adr + 1], poly_data[poly_adr + 2], poly_data[poly_adr + 3]);
863853
p0->x = poly_data[poly_adr + 4];
864854
p0->y = poly_data[poly_adr + 5];
865855
p0->z = poly_data[poly_adr + 6];
@@ -869,7 +859,7 @@ void model1_state::push_object(UINT32 tex_adr, UINT32 poly_adr, UINT32 size) {
869859

870860
int link = (flags >> 8) & 3;
871861

872-
m_view->transform_vector(&vn);
862+
m_view->transform_vector(vn);
873863

874864
m_view->transform_point(p0);
875865
m_view->transform_point(p1);
@@ -881,7 +871,7 @@ void model1_state::push_object(UINT32 tex_adr, UINT32 poly_adr, UINT32 size) {
881871
{
882872
p0->s.x = p0->s.y = 0;
883873
}
884-
874+
885875
if (p1->z > 0)
886876
{
887877
m_view->project_point(p1);
@@ -919,7 +909,7 @@ void model1_state::push_object(UINT32 tex_adr, UINT32 poly_adr, UINT32 size) {
919909
if (!(flags & 0x00004000) && view_determinant(old_p1, old_p0, p0) > 0)
920910
goto next;
921911

922-
vn.normalize();
912+
vn = glm::normalize(vn);
923913

924914
cquad.p[0] = old_p1;
925915
cquad.p[1] = old_p0;
@@ -950,22 +940,22 @@ void model1_state::push_object(UINT32 tex_adr, UINT32 poly_adr, UINT32 size) {
950940
cquad.col = scale_color(machine().pens[0x1000 | (m_tgp_ram[tex_adr - 0x40000] & 0x3ff)], MIN(1.0, ln));
951941
cquad.col = scale_color(machine().pens[0x1000 | (m_tgp_ram[tex_adr - 0x40000] & 0x3ff)], MIN(1.0, ln));
952942
#endif
953-
954-
float dif = vector_t::dot(vn, m_view->light);
955-
float spec = compute_specular(&vn, &m_view->light, dif, lightmode);
943+
944+
float dif = glm::dot(vn, m_view->light);
945+
float spec = compute_specular(vn, m_view->light, dif, lightmode);
956946
float ln = m_view->lightparams[lightmode].a + m_view->lightparams[lightmode].d * MAX(0.0f, dif) + spec;
957947
int lumval = 255.0f * MIN(1.0f, ln);
958948
int color = m_paletteram16[0x1000 | (m_tgp_ram[tex_adr - 0x40000] & 0x3ff)];
959949
int r = (color >> 0x0) & 0x1f;
960950
int g = (color >> 0x5) & 0x1f;
961951
int b = (color >> 0xA) & 0x1f;
962-
952+
963953
lumval >>= 2; //there must be a luma translation table somewhere
964954
if (lumval > 0x3f)
965955
lumval = 0x3f;
966956
else if (lumval < 0)
967957
lumval = 0;
968-
958+
969959
r = (m_color_xlat[(r << 8) | lumval | 0x0] >> 3) & 0x1f;
970960
g = (m_color_xlat[(g << 8) | lumval | 0x2000] >> 3) & 0x1f;
971961
b = (m_color_xlat[(b << 8) | lumval | 0x4000] >> 3) & 0x1f;
@@ -1280,10 +1270,7 @@ void model1_state::view_t::set_zoom(float x, float y)
12801270

12811271
void model1_state::view_t::set_light_direction(float x, float y, float z)
12821272
{
1283-
light.set_x(x);
1284-
light.set_y(y);
1285-
light.set_z(z);
1286-
light.normalize();
1273+
light = glm::normalize(glm::vec3(x, y, z));
12871274
}
12881275

12891276
void model1_state::view_t::set_translation_matrix(float* mat)

0 commit comments

Comments
 (0)