Debian Codegraph @

plugins/spritemodel/spritemodel.cpp

raw symbols SCIP
1 /*
2 Copyright (C) 2002 Dominic Clifton.
3
4 This file is part of GtkRadiant.
5
6 GtkRadiant is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 GtkRadiant is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GtkRadiant; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 //
22 // Sprite Model Plugin
23 //
24 // Code by Hydra aka Dominic Clifton
25 //
26 // Based on MD3Model source code by SPoG
27 //
28
29 #include "spritemodel.h"
30
31 void LoadSpriteModel( entity_interfaces_t *interfaces, const char *name ){
32 IShader *pShader;
33
34 pShader = QERApp_Shader_ForName( name );
35
36 if ( !pShader ) {
37 Sys_Printf( "ERROR: can't find shader (or image) for: %s\n", name );
38 return; // NULL;
39 }
40
41 CSpriteModel *model = new CSpriteModel();
42 model->Construct( pShader );
43 interfaces->pRender = (IRender*)model;
44 interfaces->pRender->IncRef();
45 //interfaces->pSelect = (ISelect*)model;
46 //interfaces->pSelect->IncRef();
47 interfaces->pSelect = NULL;
48 interfaces->pEdit = NULL;
49 model->DecRef();
50
51 }
52
53 void CSpriteModel::Construct( IShader *pShader ){
54 m_pShader = pShader;
55 aabb_clear( &m_BBox );
56 /*
57 md3Surface_t *pSurface = (md3Surface_t *)(((unsigned char *)pHeader) + pHeader->ofsSurfaces);
58 m_nSurfaces = pHeader->numSurfaces;
59 CMD3Surface* surfaces = new CMD3Surface[m_nSurfaces];
60 for (int i = 0; i < m_nSurfaces; i++ )
61 {
62 surfaces[i].Construct(pSurface);
63 pSurface = (md3Surface_t *) ((( char * ) pSurface) + pSurface->ofsEnd);
64 }
65 m_children = surfaces;
66 AccumulateBBox();
67 */
68 }
69
70 CSpriteModel::CSpriteModel(){
71 refCount = 1;
72 //m_nSurfaces = 0;
73 //m_children = NULL;
74 m_pShader = NULL;
75 }
76
77 CSpriteModel::~CSpriteModel(){
78 // if(m_children) delete[] m_children;
79 if ( m_pShader ) {
80 m_pShader->DecRef();
81 }
82 }
83
84 void CSpriteModel::Draw( int state, int rflags ) const {
85
86 /*
87 // Draw a point in the middle of the bbox
88 vec3_t middle = {0,0,0};
89 g_QglTable.m_pfn_qglPointSize (4);
90 g_QglTable.m_pfn_qglColor3f (0,1,0);
91 g_QglTable.m_pfn_qglBegin (GL_POINTS);
92 g_QglTable.m_pfn_qglVertex3fv (middle);
93 g_QglTable.m_pfn_qglEnd ();
94 */
95
96 qtexture_t *q = m_pShader->getTexture();
97
98 // convert pixels to units and divide in half again so we draw in the middle
99 // of the bbox.
100 int h = q->height / 8;
101 int w = q->width / 8;
102
103 // setup opengl stuff
104
105 g_QglTable.m_pfn_qglPushAttrib( GL_ALL_ATTRIB_BITS ); // GL_ENABLE_BIT
106 //g_QglTable.m_pfn_qglColor3f (1,1,1); //testing
107 //g_QglTable.m_pfn_qglColor4f (1,1,1,1); //testing
108 g_QglTable.m_pfn_qglBindTexture( GL_TEXTURE_2D, q->texture_number );
109
110 //g_QglTable.m_pfn_qglEnable (GL_TEXTURE_2D); // FIXME: ? this forces textures, even in wireframe mode, bad... ?
111
112 g_QglTable.m_pfn_qglAlphaFunc( GL_LESS, 1 );
113 g_QglTable.m_pfn_qglEnable( GL_ALPHA_TEST );
114
115 // get rid of this when sprite always faces camera
116 g_QglTable.m_pfn_qglDisable( GL_CULL_FACE );
117 g_QglTable.m_pfn_qglPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
118
119 // draw the sprite
120
121 #if 0
122 // using x/y axis, it appears FLAT without the proper transform and rotation.
123
124 g_QglTable.m_pfn_qglBegin( GL_QUADS );
125 g_QglTable.m_pfn_qglTexCoord2f( 0,0 );
126 g_QglTable.m_pfn_qglVertex3f( 0 - w,0 - h, 0 );
127 g_QglTable.m_pfn_qglTexCoord2f( 1,0 );
128 g_QglTable.m_pfn_qglVertex3f( w,0 - h, 0 );
129 g_QglTable.m_pfn_qglTexCoord2f( 1,1 );
130 g_QglTable.m_pfn_qglVertex3f( w, h, 0 );
131 g_QglTable.m_pfn_qglTexCoord2f( 0,1 );
132 g_QglTable.m_pfn_qglVertex3f( 0 - w, h, 0 );
133 g_QglTable.m_pfn_qglEnd();
134 #else
135
136 // so draw it using y/z instead.
137 g_QglTable.m_pfn_qglBegin( GL_QUADS );
138 g_QglTable.m_pfn_qglTexCoord2f( 0.0f, 0.0f );
139 g_QglTable.m_pfn_qglVertex3f( 0.0f, static_cast<float>( w ), static_cast<float>( h ) );
140 g_QglTable.m_pfn_qglTexCoord2f( 1.0f, 0.0f );
141 g_QglTable.m_pfn_qglVertex3f( 0.0f, 0.0f - static_cast<float>( w ), static_cast<float>( h ) );
142 g_QglTable.m_pfn_qglTexCoord2f( 1.0f, 1.0f );
143 g_QglTable.m_pfn_qglVertex3f( 0.0f, 0.0f - static_cast<float>( w ), 0.0f - static_cast<float>( h ) );
144 g_QglTable.m_pfn_qglTexCoord2f( 0.0f, 0.0f );
145 g_QglTable.m_pfn_qglVertex3f( 0.0f, static_cast<float>( w ), 0.0f - static_cast<float>( h ) );
146 g_QglTable.m_pfn_qglEnd();
147 #endif
148
149 g_QglTable.m_pfn_qglBindTexture( GL_TEXTURE_2D, 0 );
150 g_QglTable.m_pfn_qglPopAttrib();
151 }
152
153 /*
154 bool CSpriteModel::TestRay(const ray_t *ray, vec_t *dist) const
155 {
156 vec_t depth_start = *dist;
157 vec_t depth_local = *dist;
158
159 if (aabb_test_ray(&m_BBox, ray) == 0)
160 return false;
161
162 for(int i=0; i<m_nSurfaces; i++)
163 {
164 if(m_children[i].TestRay(ray, &depth_local))
165 {
166 if (depth_local < *dist) *dist = depth_local;
167 }
168 }
169
170 return *dist < depth_start;
171 }
172 */