Game Development Community

rotate buildings and turning the build image red

by Jeff Yaskus · in RTS Starter Kit · 01/20/2010 (12:06 am) · 2 replies

I'm trying to figure out where to start ... (a) I'd like to be able to rotate a building while its in the process of being placed down, perhaps by rolling the mouse scroll wheel.

And (b) to make some basic checks if its a valid build location - not seeking perfection, just something basic. I have heard of people using ray casts or such - but cant seem to find code examples. Maybe just if it overlaps another building or the slope is super high (or water??) ?

Also (c) once its placed - how to cycle it through the building -> animations ...

If not the code, or a link - can anyone at least direct me towards the appropriate files to begin digging ?

#1
01/28/2010 (12:23 am)
going to try to use the following - to get this working.

building placement

http://www.torquepowered.com/community/forums/viewthread/55962

building rotation

http://www.torquepowered.com/community/forums/viewthread/72219
#2
01/29/2010 (4:58 pm)
got building rotation working ... using some of the code from thread #55962

steps to repeat;

a) remove placebuilding entry in GuiRTSTSCtrl::on3DMouseDown()

b) add that entry into the end of GuiRTSTSCtrl::on3DMouseUp()

c) add this to the top of GUIRTSTSCtrl::3DMouseDraggged (the .cc file) -- (before the other if statements)

// If we are placing a building and the mouse is dragged, we want to rotate the building.  
    if(mPlacingBuilding){  
       Point2I localPoint = globalToLocalCoord(event.mousePoint);  
       Point2I relativePoint = mDragStart - localPoint;  
   
    // Determines what direction to rotate the building  
    F32 theta = ((atan2(float(relativePoint.y),-float(relativePoint.x)) - M_PI2) * -1);  
    if(theta < 0)  
       theta += M_2PI;  
  
    MatrixF zRot;  
    zRot.set(EulerF(0,0,theta));  
    zRot.setColumn(3,mNewBuilding->getPosition());  
    ((ShapeBase*)mNewBuilding)->setTransform(zRot);  
 }

d) add this engine/math/mPoint.h ~Lines 318-319:
Point3F  operator+(const F32&) const;
Point3F  operator-(const F32&) const;
add this to mConstants.h (anywhere)
#define M_PI2        1.57079632679489661923

e) add around Lines 1303-1312 ~(lines are after you added the two above lines, between operator- and operator+=):
inline Point3F Point3F::operator+(const F32& _constant) const
{
   return Point3F(x + _constant, y + _constant,  z + _constant);
}


inline Point3F Point3F::operator-(const F32& _constant) const
{
   return Point3F(x - _constant, y - _constant,  z - _constant);
}


and then when you are placing a building and left click, dragging the mouse will visibly rotate the building -- and letting go places it there.

AND -- most important it doesn't break the existing code for TGE 1.5.2 + RTS Kit + World Domination mod.

Would still like to turn the build icon red, when its going to collide with an existing building - resource - or slope is too steep. But moving on for now.