summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/postest.h
blob: e08b3f47022e3052ae268e2b017ef3f01e5dedac (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*---------------------------------------------------------------------------------

PosTest.c -- Code for performing hardware position testing

Copyright (C) 2007
Gabe Ghearing (gabebear)

This software is provided 'as-is', without any express or implied
warranty.  In no event will the authors be held liable for any
damages arising from the use of this software.

Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:

1.	The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.

2.	Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.

3.	This notice may not be removed or altered from any source
distribution.

---------------------------------------------------------------------------------*/
#ifndef POS_TEST_INCLUDE
#define POS_TEST_INCLUDE

#include <nds/arm9/video.h>
#include <nds/arm9/videoGL.h>

/*! \brief true if the hardware is currently performing a position/vertex/box test.
\return whether a test is being performed */
GL_STATIC_INL bool PosTestBusy() {
	return (GFX_STATUS & BIT(0))!=0;
}

/*! \file postest.h
\brief Position Test Functions.<BR>
The position test multiplies a given vector by the position matrix and returns the coords(x,y,z,w). The position test is really quick, about 10x faster than a box test.
*/

/*! \brief Starts a position test asynchronously
\param x specifies x offset from the current modelview matrix
\param y specifies y offset from the current modelview matrix
\param z specifies z offset from the current modelview matrix */
GL_STATIC_INL void PosTest_Asynch(v16 x, v16 y, v16 z){
	GFX_POS_TEST = VERTEX_PACK(x, y);
	GFX_POS_TEST = z;
}

/*! \brief Performs a position test
\param x specifies x offset from the current modelview matrix
\param y specifies y offset from the current modelview matrix
\param z specifies z offset from the current modelview matrix */
GL_STATIC_INL void PosTest(v16 x, v16 y, v16 z) {
	PosTest_Asynch(x,y,z);
	while(PosTestBusy());
}

/*! \brief Returns the distance from the camera of the last position test, pretty darn useful
\return W magnitude */
GL_STATIC_INL int32 PosTestWresult() {
	return GFX_POS_RESULT[3];
}

/*! \brief Returns absolute X position of the last position test (location if the modelview matrix was identity)
\return Absolute X position */
GL_STATIC_INL int32 PosTestXresult() {
	return GFX_POS_RESULT[0];
}

/*! \brief Returns absolute Y position of the last position test (location if the modelview matrix was identity)
\return Absolute Y position */
GL_STATIC_INL int32 PosTestYresult() {
	return GFX_POS_RESULT[1];
}

/*! \brief Returns absolute Z position of the last position test (location if the modelview matrix was identity)
\return Absolute Z position */
GL_STATIC_INL int32 PosTestZresult() {
	return GFX_POS_RESULT[2];
}

#endif // ifndef POS_TEST_INCLUDE