apply misc fixes from Markus Fischer and Rambetter
[xonotic/netradiant.git] / plugins / entity / entity_entitymodel.cpp
1 /*
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 #include <stdlib.h>
23
24 #include "entity_entitymodel.h"
25
26 void Entity_UpdateClass(entity_t *e, const char* value)
27 {
28   if(strcmp(value, "misc_model") == 0
29     || (strcmp(value, "misc_gamemodel") == 0)
30     || (strcmp(value, "model_static") == 0))
31   {
32     if (e->model.pRender) e->model.pRender->DecRef();
33     if (e->model.pSelect) e->model.pSelect->DecRef();
34     if (e->model.pEdit) e->model.pEdit->DecRef();
35     e->model.pRender = NULL;
36     e->model.pSelect = NULL;
37     e->model.pEdit = NULL;
38
39     CEntityMiscModel *model = new CEntityMiscModel(e);
40   
41     e->model.pRender = (IRender*)model;
42     e->model.pRender->IncRef();
43     e->model.pSelect = (ISelect*)model;
44     e->model.pSelect->IncRef();
45     e->model.pEdit = (IEdit*)model;
46     e->model.pEdit->IncRef();
47
48     model->DecRef();
49   }
50   else if(e->eclass && e->eclass->modelpath)
51   {
52     if (e->model.pRender) e->model.pRender->DecRef();
53     if (e->model.pSelect) e->model.pSelect->DecRef();
54     if (e->model.pEdit) e->model.pEdit->DecRef();
55     e->model.pRender = NULL;
56     e->model.pSelect = NULL;
57     e->model.pEdit = NULL;
58     
59     CEntityEclassModel *model = new CEntityEclassModel;
60
61     model->SetEclass(e->eclass);
62     model->SetName(e->eclass->modelpath);
63
64     e->model.pRender = (IRender*)model;
65     e->model.pRender->IncRef();
66     e->model.pSelect = (ISelect*)model;
67     e->model.pSelect->IncRef();
68     e->model.pEdit = (IEdit*)model;
69     e->model.pEdit->IncRef();
70
71     model->DecRef();        
72   }
73 }
74
75 void pivot_draw(const vec3_t pivot)
76 {
77   vec3_t vCenter, vMin, vMax;
78   VectorCopy(pivot, vCenter);
79
80   g_QglTable.m_pfn_qglPointSize(4);
81
82   g_QglTable.m_pfn_qglBegin(GL_POINTS);
83   g_QglTable.m_pfn_qglVertex3fv(vCenter);
84   g_QglTable.m_pfn_qglEnd();
85
86   g_QglTable.m_pfn_qglBegin(GL_LINES);
87   vCenter[0] -= 8;
88   g_QglTable.m_pfn_qglVertex3fv(vCenter);
89   vCenter[0] += 16;
90   g_QglTable.m_pfn_qglVertex3fv(vCenter);
91   vCenter[0] -= 8;
92   vCenter[1] -= 8;
93   g_QglTable.m_pfn_qglVertex3fv(vCenter);
94   vCenter[1] += 16;
95   g_QglTable.m_pfn_qglVertex3fv(vCenter);
96   vCenter[1] -= 8;
97   vCenter[2] -= 8;
98   g_QglTable.m_pfn_qglVertex3fv(vCenter);
99   vCenter[2] += 16;
100   g_QglTable.m_pfn_qglVertex3fv(vCenter);
101   vCenter[2] -= 8;
102   g_QglTable.m_pfn_qglEnd();
103
104   VectorCopy(vCenter, vMin);
105   VectorCopy(vCenter, vMax);
106   vMin[0] -= 4;
107   vMin[1] -= 4;
108   vMin[2] -= 4;
109   vMax[0] += 4;
110   vMax[1] += 4;
111   vMax[2] += 4;
112
113   g_QglTable.m_pfn_qglBegin(GL_LINE_LOOP);
114   g_QglTable.m_pfn_qglVertex3f(vMin[0],vMin[1],vMin[2]);
115   g_QglTable.m_pfn_qglVertex3f(vMax[0],vMin[1],vMin[2]);
116   g_QglTable.m_pfn_qglVertex3f(vMax[0],vMax[1],vMin[2]);
117   g_QglTable.m_pfn_qglVertex3f(vMin[0],vMax[1],vMin[2]);
118   g_QglTable.m_pfn_qglEnd();
119         
120   g_QglTable.m_pfn_qglBegin(GL_LINE_LOOP);
121   g_QglTable.m_pfn_qglVertex3f(vMin[0],vMin[1],vMax[2]);
122   g_QglTable.m_pfn_qglVertex3f(vMax[0],vMin[1],vMax[2]);
123   g_QglTable.m_pfn_qglVertex3f(vMax[0],vMax[1],vMax[2]);
124   g_QglTable.m_pfn_qglVertex3f(vMin[0],vMax[1],vMax[2]);
125   g_QglTable.m_pfn_qglEnd();
126   
127   g_QglTable.m_pfn_qglBegin(GL_LINES);
128   g_QglTable.m_pfn_qglVertex3f(vMin[0],vMin[1],vMin[2]);
129   g_QglTable.m_pfn_qglVertex3f(vMin[0],vMin[1],vMax[2]);
130   g_QglTable.m_pfn_qglVertex3f(vMin[0],vMax[1],vMax[2]);
131   g_QglTable.m_pfn_qglVertex3f(vMin[0],vMax[1],vMin[2]);
132   g_QglTable.m_pfn_qglVertex3f(vMax[0],vMin[1],vMin[2]);
133   g_QglTable.m_pfn_qglVertex3f(vMax[0],vMin[1],vMax[2]);
134   g_QglTable.m_pfn_qglVertex3f(vMax[0],vMax[1],vMax[2]);
135   g_QglTable.m_pfn_qglVertex3f(vMax[0],vMax[1],vMin[2]);
136   g_QglTable.m_pfn_qglEnd();
137 }
138