summaryrefslogtreecommitdiff
path: root/plugins/peopsxgl/gte_accuracy.c
blob: a2f47cbdf192a474ccfec1b65e83f6d3cb8954b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/***************************************************************************
 *   Copyright (C) 2011 by Blade_Arma                                      *
 *                                                                         *
 *   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; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   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 for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
 ***************************************************************************/

#include "stdafx.h"
#include "externals.h"

#include <math.h>

// TODO: use malloc and pointer to the array's center.
float gteCoords[0x800 * 2][0x800 * 2][2];

void CALLBACK GPUaddVertex(short sx, short sy, long long fx, long long fy, long long fz)
{
	if(bGteAccuracy)
	{
		if(sx >= -0x800 && sx <= 0x7ff &&
		   sy >= -0x800 && sy <= 0x7ff)
		{
			gteCoords[sy + 0x800][sx + 0x800][0] = fx / 65536.0f;
			gteCoords[sy + 0x800][sx + 0x800][1] = fy / 65536.0f;
		}
	}
}

void resetGteVertices()
{
	if(bGteAccuracy)
	{
		memset(gteCoords, 0x00, sizeof(gteCoords));
	}
}

int getGteVertex(short sx, short sy, float *fx, float *fy)
{
	if(bGteAccuracy)
	{
		if(sx >= -0x800 && sx <= 0x7ff &&
		   sy >= -0x800 && sy <= 0x7ff)
		{
			if((fabsf(gteCoords[sy + 0x800][sx + 0x800][0] - sx) < 1.0) &&
			   (fabsf(gteCoords[sy + 0x800][sx + 0x800][1] - sy) < 1.0))
			{
				*fx = gteCoords[sy + 0x800][sx + 0x800][0];
				*fy = gteCoords[sy + 0x800][sx + 0x800][1];
				
				return 1;
			}
		}
	}
	
	return 0;
}