1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     demo_RenderData.cpp
4 
5   Copyright (C)2009-2012 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev: 46365 $
14  *---------------------------------------------------------------------------*/
15 
16 #include "demo/RenderData/demo_RenderData.h"
17 
18 namespace demo
19 {
20 
GetLcdWidth(const s32 display)21     f32 GetLcdWidth(const s32 display)
22     {
23         if ( display == NN_GX_DISPLAY0 )
24         {
25             return NN_GX_DISPLAY0_WIDTH;
26         }
27         else if ( display == NN_GX_DISPLAY1 )
28         {
29             return NN_GX_DISPLAY1_WIDTH;
30         }
31         else
32         {
33             return NN_GX_DISPLAY0_WIDTH;
34         }
35     }
36 
GetLcdHeight(const s32 display)37     f32 GetLcdHeight(const s32 display)
38     {
39         if ( display == NN_GX_DISPLAY0 )
40         {
41             return NN_GX_DISPLAY0_HEIGHT;
42         }
43         else if ( display == NN_GX_DISPLAY1 )
44         {
45             return NN_GX_DISPLAY1_HEIGHT;
46         }
47         else
48         {
49             return NN_GX_DISPLAY0_HEIGHT;
50         }
51     }
52 
53 /* ------------------------------------------------------------------------
54          RenderData class  member function
55    ------------------------------------------------------------------------ */
56 
RenderData(void)57     RenderData::RenderData(void) :
58     m_RenderTarget(NN_GX_DISPLAY0),
59     m_WindowWidth(NN_GX_DISPLAY0_WIDTH), m_WindowHeight(NN_GX_DISPLAY0_HEIGHT),
60     m_InverseWindowWidth(1.0f / NN_GX_DISPLAY0_WIDTH), m_InverseWindowHeight(1.0f / NN_GX_DISPLAY0_HEIGHT)
61     {
62         m_WindowWidth = GetLcdWidth(m_RenderTarget);
63         m_WindowHeight = GetLcdHeight(m_RenderTarget);
64 
65         CalculateInverseWindowSize();
66     }
67 
~RenderData()68     RenderData::~RenderData()
69     {
70     }
71 
Initialize(void)72     void RenderData::Initialize(void)
73     {
74     }
75 
Finalize(void)76     void RenderData::Finalize(void)
77     {
78     }
79 
SetWindowSize(const f32 windowWidth,const f32 windowHeight)80     void RenderData::SetWindowSize(const f32 windowWidth, const f32 windowHeight)
81     {
82         m_WindowWidth = windowWidth;
83         m_WindowHeight = windowHeight;
84 
85         CalculateInverseWindowSize();
86     }
87 
GetNormalizedDeviceCoordinateXY(const f32 windowCoordinateX,const f32 windowCoordinateY,f32 & normalizedDeviceCoordinateX,f32 & normalizedDeviceCoordinateY)88     void RenderData::GetNormalizedDeviceCoordinateXY(const f32 windowCoordinateX, const f32 windowCoordinateY,
89         f32& normalizedDeviceCoordinateX, f32& normalizedDeviceCoordinateY)
90     {
91         normalizedDeviceCoordinateX = GetNormalizedDeviceCoordinateX(m_WindowWidth - windowCoordinateY);
92         normalizedDeviceCoordinateY = GetNormalizedDeviceCoordinateY(windowCoordinateX);
93     }
94 
GetNormalizedDeviceCoordinateX(const f32 windowCoordinateY)95     f32 RenderData::GetNormalizedDeviceCoordinateX(const f32 windowCoordinateY)
96     {
97         return (windowCoordinateY * 2.0f * m_InverseWindowWidth) - 1.0f;
98     }
99 
GetNormalizedDeviceCoordinateY(const f32 windowCoordinateX)100     f32 RenderData::GetNormalizedDeviceCoordinateY(const f32 windowCoordinateX)
101     {
102         return 1.0f - (windowCoordinateX * 2.0f * m_InverseWindowHeight);
103     }
104 
CalculateInverseWindowSize(void)105     void RenderData::CalculateInverseWindowSize(void)
106     {
107         if ( m_WindowWidth > 0.0f )
108         {
109             m_InverseWindowWidth = 1.0f / m_WindowWidth;
110         }
111         else
112         {
113             NN_TPANIC_("Invalid windowWidth = %d\n", m_WindowWidth);
114         }
115 
116         if ( m_WindowHeight > 0.0f )
117         {
118             m_InverseWindowHeight = 1.0f / m_WindowHeight;
119         }
120         else
121         {
122             NN_TPANIC_("Invalid windowHeight = %d\n", m_WindowHeight);
123         }
124     }
125 }
126