2 BobToolz plugin for GtkRadiant
3 Copyright (C) 2001 Gordon Biggans
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "DTreePlanter.h"
22 #include "funchandlers.h"
24 bool DTreePlanter::OnMouseMove(guint32 nFlags, gdouble x, gdouble y) {
28 bool DTreePlanter::OnLButtonDown(guint32 nFlags, gdouble x, gdouble y) {
29 VIEWTYPE vt = m_XYWrapper->GetViewType();
42 m_XYWrapper->SnapToGrid( static_cast< int >( x ), static_cast< int >( y ), pt );
44 if(FindDropPoint(pt, vhit)) {
50 sprintf(buffer, "%i %i %i", (int)vhit[0], (int)vhit[1], (int)vhit[2]);
51 e.AddEPair("origin", buffer);
54 entity_t* pLastEntity = NULL;
55 entity_t* pThisEntity = NULL;
57 int entNum = -1, lastEntNum = -1, entpos;
58 for(int i = 0; i < 256; i++) {
59 sprintf(buffer, m_linkName, i);
60 pThisEntity = FindEntityFromTargetname( buffer, &entNum );
65 pLastEntity = pThisEntity;
70 sprintf(buffer, m_linkName, 0);
72 sprintf(buffer, m_linkName, entpos + 1);
75 e.AddEPair( "targetname", buffer );
79 e2.LoadFromEntity(lastEntNum, TRUE);
80 e2.AddEPair("target", buffer);
81 e2.RemoveFromRadiant();
82 e2.BuildInRadiant(FALSE);
87 int angleYaw = (rand() % (m_maxYaw - m_minYaw + 1)) + m_minYaw;
88 int anglePitch = (rand() % (m_maxPitch - m_minPitch + 1)) + m_minPitch;
90 sprintf(buffer, "%i %i 0", anglePitch, angleYaw);
91 e.AddEPair("angles", buffer);
95 int treetype = rand() % m_numModels;
96 e.AddEPair("model", m_trees[treetype].name);
100 float scale = (((rand()%1000)*0.001f) * (m_maxScale - m_minScale)) + m_minScale;
102 sprintf(buffer, "%f", scale );
103 e.AddEPair("modelscale", buffer);
106 e.BuildInRadiant( FALSE );
116 bool DTreePlanter::OnLButtonUp(guint32 nFlags, gdouble x, gdouble y) {
120 bool DTreePlanter::OnRButtonDown(guint32 nFlags, gdouble x, gdouble y) {
124 bool DTreePlanter::OnRButtonUp(guint32 nFlags, gdouble x, gdouble y) {
128 bool DTreePlanter::OnMButtonDown(guint32 nFlags, gdouble x, gdouble y) {
132 bool DTreePlanter::OnMButtonUp(guint32 nFlags, gdouble x, gdouble y) {
136 bool DTreePlanter::FindDropPoint(vec3_t in, vec3_t out) {
140 vec3_t vUp = { 0, 0, 1 };
141 vec3_t vForward = { 0, 1, 0 };
142 vec3_t vLeft = { 1, 0, 0 };
146 VectorCopy(in, p1.points[0]);
147 VectorCopy(in, p1.points[1]);
148 VectorCopy(in, p1.points[2]);
149 VectorMA(p1.points[1], 20, vUp, p1.points[1]);
150 VectorMA(p1.points[1], 20, vLeft, p1.points[2]);
152 VectorCopy(in, p2.points[0]);
153 VectorCopy(in, p2.points[1]);
154 VectorCopy(in, p2.points[2]);
155 VectorMA(p1.points[1], 20, vUp, p2.points[1]);
156 VectorMA(p1.points[1], 20, vForward, p2.points[2]);
164 int cnt = m_world.GetIDMax();
165 for(int i = 0; i < cnt; i++) {
166 DBrush* pBrush = m_world.GetBrushForID( i );
168 if(pBrush->IntersectsWith( &p1, &p2, temp )) {
171 VectorSubtract(in, temp, diff);
172 tempdist = VectorLength( diff );
173 if(!found || (tempdist < dist)) {
175 VectorCopy( temp, out );
184 void DTreePlanter::DropEntsToGround( void ) {
185 // tell Radiant we want to access the selected brushes
186 g_FuncTable.m_pfnAllocateSelectedBrushHandles();
190 int cnt = g_FuncTable.m_pfnSelectedBrushCount();
191 for(int i = 0; i < cnt; i++) {
192 brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle(i);
194 ent.LoadFromEntity(brush->owner, TRUE);
196 DEPair* pEpair = ent.FindEPairByKey("origin");
202 sscanf( pEpair->value.GetBuffer(), "%f %f %f", &vec[0], &vec[1], &vec[2]);
204 FindDropPoint( vec, out );
207 sprintf( buffer, "%f %f %f", out[0], out[1], out[2] );
208 ent.AddEPair( "origin", buffer );
209 ent.RemoveFromRadiant();
210 ent.BuildInRadiant(FALSE);
213 g_FuncTable.m_pfnReleaseSelectedBrushHandles();
216 void DTreePlanter::MakeChain( void ) {
220 for(i = 0; i < m_linkNum; i++) {
221 DEntity e("info_train_spline_main");
223 sprintf( buffer, "%s_pt%i", m_linkName, i );
224 e.AddEPair( "targetname", buffer );
226 sprintf( buffer, "0 %i 0", i * 64 );
227 e.AddEPair( "origin", buffer );
229 if(i != m_linkNum-1) {
230 sprintf( buffer, "%s_pt%i", m_linkName, i+1 );
231 e.AddEPair( "target", buffer );
233 sprintf( buffer, "%s_ctl%i", m_linkName, i );
234 e.AddEPair( "control", buffer );
237 e.BuildInRadiant( FALSE );
240 for(i = 0; i < m_linkNum-1; i++) {
241 DEntity e("info_train_spline_control");
243 sprintf( buffer, "%s_ctl%i", m_linkName, i );
244 e.AddEPair( "targetname", buffer );
246 sprintf( buffer, "0 %i 0", (i * 64) + 32);
247 e.AddEPair( "origin", buffer );
249 e.BuildInRadiant( FALSE );
253 void DTreePlanter::SelectChain( void ) {
256 for(int i = 0; i < m_linkNum; i++) {
257 DEntity e("info_train_spline_main");
259 sprintf( buffer, "%s_pt%i", m_linkName, i );
260 e.AddEPair( "targetname", buffer );
262 sprintf( buffer, "0 %i 0", i * 64 );
263 e.AddEPair( "origin", buffer );
265 if(i != m_linkNum-1) {
266 sprintf( buffer, "%s_pt%i", m_linkName, i+1 );
267 e.AddEPair( "target", buffer );
269 sprintf( buffer, "%s_ctl%i", m_linkName, i );
270 e.AddEPair( "control", buffer );
273 e.BuildInRadiant( FALSE );
276 for(int i = 0; i < m_linkNum-1; i++) {
277 DEntity e("info_train_spline_control");
279 sprintf( buffer, "%s_ctl%i", m_linkName, i );
280 e.AddEPair( "targetname", buffer );
282 sprintf( buffer, "0 %i 0", (i * 64) + 32);
283 e.AddEPair( "origin", buffer );
285 e.BuildInRadiant( FALSE );