bool GetEntityCentre( const char* entity, vec3_t centre ) { entity_s* ent = FindEntityFromTargetname( entity, NULL ); if ( !ent ) { return FALSE; } int cnt = g_FuncTable.m_pfnAllocateEntityBrushHandles( ent ); if ( cnt == 0 ) { g_FuncTable.m_pfnReleaseEntityBrushHandles(); return FALSE; } brush_t* brush = (brush_t*)g_FuncTable.m_pfnGetEntityBrushHandle( 0 ); DBrush cBrush; cBrush.LoadFromBrush_t( brush, FALSE ); vec3_t min, max; cBrush.GetBounds( min, max ); VectorAdd( min, max, centre ); VectorScale( centre, 0.5f, centre ); g_FuncTable.m_pfnReleaseEntityBrushHandles(); return TRUE; }
void DoPathPlotter(){ PathPlotterRS rs; int ret = DoPathPlotterBox( &rs ); if ( ret == IDCANCEL ) { return; } if ( ret == IDNO ) { if ( g_PathView ) { delete g_PathView; } return; } if ( g_FuncTable.m_pfnSelectedBrushCount() != 1 ) { DoMessageBox( "Invalid number of brushes selected, chose 1 only", "Error", MB_OK ); return; } // tell Radiant we want to access the selected brushes g_FuncTable.m_pfnAllocateSelectedBrushHandles(); brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle( 0 ); // should be our trigger brush DEntity world; world.LoadEPairList( *g_EntityTable.m_pfnGetEntityKeyValList( brush->owner ) ); DEPair* trigger_ep = world.FindEPairByKey( "targetname" ); if ( trigger_ep ) { if ( !strcmp( world.m_Classname, "trigger_push" ) ) { DEPair* target_ep = world.FindEPairByKey( "target" ); if ( target_ep ) { entity_s* entTarget = FindEntityFromTargetname( target_ep->value, NULL ); if ( entTarget ) { if ( g_PathView ) { delete g_PathView; } g_PathView = new DBobView; g_PathView->Begin( trigger_ep->value, target_ep->value, rs.fMultiplier, rs.nPoints, rs.fGravity, rs.bNoUpdate, rs.bShowExtra ); } else{ DoMessageBox( "trigger_push target could not be found.", "Error", MB_OK ); } } else{ DoMessageBox( "trigger_push has no target.", "Error", MB_OK ); } } else{ DoMessageBox( "You must select a 'trigger_push' entity.", "Error", MB_OK ); } } else{ DoMessageBox( "Entity must have a targetname", "Error", MB_OK ); } g_FuncTable.m_pfnReleaseSelectedBrushHandles(); }
bool GetEntityCentre(const char* entity, vec3_t centre) { const scene::Path* ent = FindEntityFromTargetname(entity); if(!ent) return false; scene::Instance& instance = *GlobalSceneGraph().find(*ent); VectorCopy(instance.worldAABB().origin, centre); return true; }
void DBobView_setEntity( Entity& entity, float multiplier, int points, float varGravity, bool bNoUpdate, bool bShowExtra ){ DEntity trigger; trigger.LoadEPairList( &entity ); DEPair* trigger_ep = trigger.FindEPairByKey( "targetname" ); if ( trigger_ep ) { if ( !strcmp( trigger.m_Classname, "trigger_push" ) ) { DEPair* target_ep = trigger.FindEPairByKey( "target" ); if ( target_ep ) { const scene::Path* entTarget = FindEntityFromTargetname( target_ep->value ); if ( entTarget ) { if ( g_PathView ) { delete g_PathView; } g_PathView = new DBobView; Entity* target = Node_getEntity( entTarget->top() ); if ( target != 0 ) { if ( !bNoUpdate ) { g_PathView->trigger = &entity; entity.attach( *g_PathView ); g_PathView->target = target; target->attach( *g_PathView ); } g_PathView->Begin( trigger_ep->value, target_ep->value, multiplier, points, varGravity, bNoUpdate, bShowExtra ); } else{ globalErrorStream() << "bobToolz PathPlotter: trigger_push ARGH\n"; } } else{ globalErrorStream() << "bobToolz PathPlotter: trigger_push target could not be found..\n"; } } else{ globalErrorStream() << "bobToolz PathPlotter: trigger_push has no target..\n"; } } else{ globalErrorStream() << "bobToolz PathPlotter: You must select a 'trigger_push' entity..\n"; } } else{ globalErrorStream() << "bobToolz PathPlotter: Entity must have a targetname.\n"; } return; }
SignalHandlerResult DTreePlanter::mouseDown(const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers) { if(button != c_buttonLeft) { return SIGNAL_CONTINUE_EMISSION; } VIEWTYPE vt = GlobalRadiant().XYWindow_getViewType(); switch(vt) { case XY: break; case YZ: case XZ: default: return SIGNAL_CONTINUE_EMISSION; } Vector3 pt, vhit; pt = vector3_snapped(GlobalRadiant().XYWindow_windowToWorld(position), GlobalRadiant().getGridSize()); if(FindDropPoint(vector3_to_array(pt), vector3_to_array(vhit))) { vhit[2] += m_offset; char buffer[128]; DEntity e(m_entType); sprintf(buffer, "%i %i %i", (int)vhit[0], (int)vhit[1], (int)vhit[2]); e.AddEPair("origin", buffer); if(m_autoLink) { const scene::Path* pLastEntity = NULL; const scene::Path* pThisEntity = NULL; int entpos; for(int i = 0; i < 256; i++) { sprintf(buffer, m_linkName, i); pThisEntity = FindEntityFromTargetname( buffer ); if(pThisEntity) { entpos = i; pLastEntity = pThisEntity; } } if(!pLastEntity) { sprintf(buffer, m_linkName, 0); } else { sprintf(buffer, m_linkName, entpos + 1); } e.AddEPair( "targetname", buffer ); if(pLastEntity) { DEntity e2; e2.LoadFromEntity(pLastEntity->top(), true); e2.AddEPair("target", buffer); e2.RemoveFromRadiant(); e2.BuildInRadiant(false); } } if(m_setAngles) { int angleYaw = (rand() % (m_maxYaw - m_minYaw + 1)) + m_minYaw; int anglePitch = (rand() % (m_maxPitch - m_minPitch + 1)) + m_minPitch; sprintf(buffer, "%i %i 0", anglePitch, angleYaw); e.AddEPair("angles", buffer); } if(m_numModels) { int treetype = rand() % m_numModels; e.AddEPair("model", m_trees[treetype].name); } if(m_useScale) { float scale = (((rand()%1000)*0.001f) * (m_maxScale - m_minScale)) + m_minScale; sprintf(buffer, "%f", scale ); e.AddEPair("modelscale", buffer); } e.BuildInRadiant( false ); } if(m_autoLink) { DoTrainPathPlot(); } return SIGNAL_STOP_EMISSION; }