1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<HTML>
3<HEAD>
4<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
5<META name="GENERATOR" content="Microsoft FrontPage 5.0">
6<META http-equiv="Content-Style-Type" content="text/css">
7<LINK rel="stylesheet" type="text/css" href="../../CSS/revolution.css">
8<TITLE>GXNormal[n][t]</TITLE>
9</HEAD>
10<BODY>
11<H1 align="left">GXNormal</H1>
12<H2>C Specification</H2>
13<DL>
14  <DD>
15<PRE><CODE>#include &lt;revolution/gx.h&gt;</CODE></PRE>
16  <DD>
17<PRE><CODE>void GXNormal3f32( f32 x, f32 y, f32 z );
18void GXNormal3s16( s16 x, s16 y, s16 z );
19void GXNormal3s8 ( s8  x, s8  y, s8  z );
20
21void GXNormal1x16( u16 index );
22void GXNormal1x8 ( u8  index );</CODE></PRE>
23</DL>
24<H2>Arguments</H2>
25<P>Will depend on the function being called.</P>
26<H2>Return Values</H2>
27<P>None.</P>
28<H2>Description</H2>
29<P>These functions are used to specify normal data for a vertex.&nbsp;They can only be called between the <a href="GXBegin.html"><code>GXBegin</code></a> and <a href="GXEnd.html"><code>GXEnd</code></a> functions.&nbsp;Function names take the following format:</P>
30<P><CODE>GXNormal[n][t]</CODE></P>
31<P> </P>
32<P>The function name parameter <CODE>n</CODE> is one of the {1, 3} and describes the number of arguments to the function. The function name parameter <CODE>t</CODE> is one of the {s8, s16, f32, x8, x16} and describes the type of each argument to the function.&nbsp;The type name indicates signed (s), floating point (f), and index (x) data types.&nbsp;The number after the type indicates the size in bits. E.g., <code>s8</code> indicates a signed 8-bit quantity.&nbsp;Consequently, <code>GXNormal3f32</code> takes 3 floating-point arguments.</P>
33<P>The selected function must correspend to the current vertex descriptor and the vertex attribute format specified in <CODE>GXBegin</CODE>.&nbsp;The current vertex descriptor is set using the <a href="GXSetVtxDesc.html"><code>GXSetVtxDesc</code></a> function.&nbsp;The vertex attribute format is set using <a href="GXSetVtxAttrFmt.html"><code>GXSetVtxAttrFmt</code></a>.</P>
34<P>There are two types for normals; <code>GX_VA_NRM</code> and <code>GX_VA_NBT</code>. The attribute <code>GX_VA_NRM</code> is a 3 element normal (i.e. one normalized vector).&nbsp;The attribute <code>GX_VA_NBT</code> specifies instead 3 normalized vectors (each with 3 components): normal, binormal and tangent. These three vectors are usually orthogonal and are used for bump mapping and other special rendering techniques. To specify directly referenced data for a <code>GX_VA_NBT</code> attribute, simply call the appropriate <code>GXNormal[n][t]</code> function three times. For example:</P>
35<P><CODE>GXBegin(GX_TRIANGLES, GX_VTXFMT0, n);<BR> &nbsp;&nbsp;&nbsp; GXPosition3f32 ( px, py, pz );<BR> &nbsp;&nbsp;&nbsp; GXNormal3f32&nbsp;&nbsp; ( nx, ny, nz );<BR> &nbsp;&nbsp;&nbsp; GXNormal3f32&nbsp;&nbsp; ( bx, by, bz );<BR> &nbsp;&nbsp;&nbsp; GXNormal3f32&nbsp;&nbsp; ( tx, ty, tz );<BR> &nbsp;&nbsp;&nbsp; // ...<BR> GXEnd();</CODE></P>
36<P>For <CODE>GX_VA_NBT</CODE>, indexed data can be divided and specified for each normal. Furthermore, each of the three normals that comprise the NBT has an implicit offset. For divided indices, the attribute address is calculated as follows:</P>
37
38<P><SUB><IMG border="0" src="../images/image115.gif" width="784" height="85"></SUB></P>
39<P>The application specifies separated NBT indices by specifying a component count of <CODE>GX_NRM_NBT3</CODE> in <CODE>GXSetVtxAttrFmt</CODE>. When matched with a vertex descriptor that specifies indexed normals, this combination specifies that three separate indices will be provided instead of just one.</P>
40<P>There are two ways to set up a normal table for NBT normals. One is to set up three interleaved tables. This method is straightforward, because the built-in NBT offset takes care of choosing the right value from the interleaved tables. The other method is to set up a single table (after all, a normal is a normal regardless of the name). To implement this method, you must take into account the NBT offsets and adjust the indices used in order to cancel out the offsets. In other words, it would be as follows.</P>
41<P><SUB><IMG border="0" src="../images/image116.gif" width="509" height="116"></SUB></P>
42
43<P>The order in which vertex functions must be called is specified by&nbsp;the <a href="GXSetVtxDesc.html"><code>GXSetVtxDesc</code></a> function.&nbsp;Each vertex must send attributes (positions, colors, normals, etc.) in the specified order to guarantee proper interpretation by the graphics hardware.&nbsp;</P>
44<P>When an attribute is indexed (i.e., its type, set by <a href="GXSetVtxDesc.html"><code>GXSetVtxDesc</code></a>, is <code>GX_INDEX8</code> or <code>GX_INDEX16</code>), the vertex function will specify an index to the data, not the data itself.&nbsp;The location of the array that will be indexed is disclosed using <a href="GXSetArray.html"><code>GXSetArray</code></a>. When an attribute is direct (i.e., its type, set by <a href="GXSetVtxDesc.html"><code>GXSetVtxDesc</code></a>, is <code>GX_DIRECT</code>), the vertex function sends the data.&nbsp;No vertex function should be called for an attribute which is disabled (i.e., its type, set by <a href="GXSetVtxDesc.html"><code>GXSetVtxDesc</code></a>, is <code>GX_NONE</code>).&nbsp;However, every vertex must at least enable <code>GX_VA_POS</code>.</P>
45<P>The <code>GXNormal[n][t]</code> functions are implemented as inline functions in the non-debug version of the GX library for optimal performance.&nbsp;The <code>GXNormal[n][t]</code> functions are implemented as functions in the debug version of the library so it can verify the correct order of vertex function calls between <CODE><a href="GXBegin.html">GXBegin</a></CODE> and <CODE><a href="GXEnd.html">GXEnd</a></CODE> (a common source of errors).</P>
46<H2>See Also</H2>
47<P><CODE><A href="GXBegin.html">GXBegin</A>&nbsp;&nbsp;<BR> <A href="GXEnd.html">GXEnd</A><BR> <A href="GXSetVtxDesc.html">GXSetVtxDesc</A><BR> <A href="GXSetVtxAttrFmt.html">GXSetVtxAttrFmt</A></CODE></P>
48<H2>Revision History</H2>
49<P>2006/03/01 Initial version.</P>