2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
29 #include "../idlib/precompiled.h"
32 #include "DeviceContext.h"
34 #include "UserInterfaceLocal.h"
35 #include "RenderWindow.h"
37 idRenderWindow::idRenderWindow(idDeviceContext *d, idUserInterfaceLocal *g) : idWindow(d, g) {
43 idRenderWindow::idRenderWindow(idUserInterfaceLocal *g) : idWindow(g) {
48 idRenderWindow::~idRenderWindow() {
49 renderSystem->FreeRenderWorld( world );
52 void idRenderWindow::CommonInit() {
53 world = renderSystem->AllocRenderWorld();
55 lightOrigin = idVec4(-128.0f, 0.0f, 0.0f, 1.0f);
56 lightColor = idVec4(1.0f, 1.0f, 1.0f, 1.0f);
58 viewOffset = idVec4(-128.0f, 0.0f, 0.0f, 1.0f);
63 updateAnimation = true;
67 void idRenderWindow::BuildAnimation(int time) {
69 if (!updateAnimation) {
73 if (animName.Length() && animClass.Length()) {
74 worldEntity.numJoints = worldEntity.hModel->NumJoints();
75 worldEntity.joints = ( idJointMat * )Mem_Alloc16( worldEntity.numJoints * sizeof( *worldEntity.joints ) );
76 modelAnim = gameEdit->ANIM_GetAnimFromEntityDef(animClass, animName);
78 animLength = gameEdit->ANIM_GetLength(modelAnim);
79 animEndTime = time + animLength;
82 updateAnimation = false;
86 void idRenderWindow::PreRender() {
88 world->InitFromMap( NULL );
90 spawnArgs.Set("classname", "light");
91 spawnArgs.Set("name", "light_1");
92 spawnArgs.Set("origin", lightOrigin.ToVec3().ToString());
93 spawnArgs.Set("_color", lightColor.ToVec3().ToString());
94 gameEdit->ParseSpawnArgsToRenderLight( &spawnArgs, &rLight );
95 lightDef = world->AddLightDef( &rLight );
96 if ( !modelName[0] ) {
97 common->Warning( "Window '%s' in gui '%s': no model set", GetName(), GetGui()->GetSourceFile() );
99 memset( &worldEntity, 0, sizeof( worldEntity ) );
101 spawnArgs.Set("classname", "func_static");
102 spawnArgs.Set("model", modelName);
103 spawnArgs.Set("origin", modelOrigin.c_str());
104 gameEdit->ParseSpawnArgsToRenderEntity( &spawnArgs, &worldEntity );
105 if ( worldEntity.hModel ) {
106 idVec3 v = modelRotate.ToVec3();
107 worldEntity.axis = v.ToMat3();
108 worldEntity.shaderParms[0] = 1;
109 worldEntity.shaderParms[1] = 1;
110 worldEntity.shaderParms[2] = 1;
111 worldEntity.shaderParms[3] = 1;
112 modelDef = world->AddEntityDef( &worldEntity );
118 void idRenderWindow::Render( int time ) {
119 rLight.origin = lightOrigin.ToVec3();
120 rLight.shaderParms[SHADERPARM_RED] = lightColor.x();
121 rLight.shaderParms[SHADERPARM_GREEN] = lightColor.y();
122 rLight.shaderParms[SHADERPARM_BLUE] = lightColor.z();
123 world->UpdateLightDef(lightDef, &rLight);
124 if ( worldEntity.hModel ) {
125 if (updateAnimation) {
126 BuildAnimation(time);
129 if (time > animEndTime) {
130 animEndTime = time + animLength;
132 gameEdit->ANIM_CreateAnimFrame(worldEntity.hModel, modelAnim, worldEntity.numJoints, worldEntity.joints, animLength - (animEndTime - time), vec3_origin, false );
134 worldEntity.axis = idAngles(modelRotate.x(), modelRotate.y(), modelRotate.z()).ToMat3();
135 world->UpdateEntityDef(modelDef, &worldEntity);
142 void idRenderWindow::Draw(int time, float x, float y) {
146 memset( &refdef, 0, sizeof( refdef ) );
147 refdef.vieworg = viewOffset.ToVec3();;
148 //refdef.vieworg.Set(-128, 0, 0);
150 refdef.viewaxis.Identity();
151 refdef.shaderParms[0] = 1;
152 refdef.shaderParms[1] = 1;
153 refdef.shaderParms[2] = 1;
154 refdef.shaderParms[3] = 1;
156 refdef.x = drawRect.x;
157 refdef.y = drawRect.y;
158 refdef.width = drawRect.w;
159 refdef.height = drawRect.h;
161 refdef.fov_y = 2 * atan((float)drawRect.h / drawRect.w) * idMath::M_RAD2DEG;
164 world->RenderScene(&refdef);
167 void idRenderWindow::PostParse() {
168 idWindow::PostParse();
173 idWinVar *idRenderWindow::GetWinVarByName(const char *_name, bool fixup, drawWin_t** owner ) {
175 if (idStr::Icmp(_name, "model") == 0) {
178 if (idStr::Icmp(_name, "anim") == 0) {
181 if (idStr::Icmp(_name, "lightOrigin") == 0) {
184 if (idStr::Icmp(_name, "lightColor") == 0) {
187 if (idStr::Icmp(_name, "modelOrigin") == 0) {
190 if (idStr::Icmp(_name, "modelRotate") == 0) {
193 if (idStr::Icmp(_name, "viewOffset") == 0) {
196 if (idStr::Icmp(_name, "needsRender") == 0) {
202 return idWindow::GetWinVarByName(_name, fixup, owner);
206 bool idRenderWindow::ParseInternalVar(const char *_name, idParser *src) {
207 if (idStr::Icmp(_name, "animClass") == 0) {
208 ParseString(src, animClass);
211 return idWindow::ParseInternalVar(_name, src);