mirror of
https://github.com/tribes2/engine.git
synced 2026-07-11 22:44:36 +00:00
t2 engine svn checkout
This commit is contained in:
commit
ff569bd2ae
988 changed files with 394180 additions and 0 deletions
109
hud/hudBarBaseCtrl.cc
Normal file
109
hud/hudBarBaseCtrl.cc
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hudBarBaseCtrl.h"
|
||||
|
||||
//===========================================================================
|
||||
// HudBarBaseCtrl Implementation
|
||||
//===========================================================================
|
||||
|
||||
IMPLEMENT_CONOBJECT( HudBarBaseCtrl );
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//---------------------------------------------------------------------------
|
||||
HudBarBaseCtrl::HudBarBaseCtrl() {
|
||||
mPulseRate = 500;
|
||||
mPulseThreshold = 0.3f;
|
||||
mVerticalFill = false;
|
||||
mPulse = false;
|
||||
mDisplayMounted = false;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// onWake
|
||||
//
|
||||
// This method is called when this HUD object is revived from a waiting state
|
||||
//
|
||||
// Return: True if successfuly awakened
|
||||
//---------------------------------------------------------------------------
|
||||
bool HudBarBaseCtrl::onWake() {
|
||||
if( !Parent::onWake() )
|
||||
return( false );
|
||||
return( true );
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// onSleep
|
||||
//
|
||||
// This method is used to put this HUD object in a waiting state
|
||||
//---------------------------------------------------------------------------
|
||||
void HudBarBaseCtrl::onSleep() {
|
||||
Parent::onSleep();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// onRender
|
||||
//
|
||||
// This method is used to tell the bar to render itself
|
||||
//
|
||||
// offset - A offset value for where to render the bar
|
||||
//---------------------------------------------------------------------------
|
||||
void HudBarBaseCtrl::onRender( Point2I offset, const RectI & /*updateRect*/, GuiControl * /*firstResponder*/ ) {
|
||||
|
||||
// Why is this code here?
|
||||
/*
|
||||
GameConnection *con = GameConnection::getServerConnection();
|
||||
if(!con)
|
||||
return;
|
||||
|
||||
ShapeBase * obj = con->getControlObject();
|
||||
|
||||
if( !obj )
|
||||
return;
|
||||
*/
|
||||
|
||||
F32 val = getValue();
|
||||
|
||||
RectI rect( offset + mSubRegion.point, mSubRegion.extent );
|
||||
rect.extent.x = (S32)( rect.extent.x * val );
|
||||
|
||||
mFillColor.alpha = mOpacity;
|
||||
ColorI fill;
|
||||
getBarColor( fill );
|
||||
fill.alpha = mOpacity * 255;
|
||||
|
||||
if( mPulse && ( mPulseRate != 0 ) ) {
|
||||
S32 time = (S32)Platform::getVirtualMilliseconds();
|
||||
F32 alpha = F32( time % mPulseRate ) / F32( mPulseRate / 2 );
|
||||
|
||||
if( alpha > 1 )
|
||||
alpha = 1.f - ( alpha - 1.f );
|
||||
|
||||
fill.alpha *= alpha;
|
||||
fill.alpha *= 255;
|
||||
}
|
||||
|
||||
dglDrawRectFill( rect, fill );
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// initPersistFields
|
||||
//
|
||||
// Registers datamembers of this object with the game
|
||||
//---------------------------------------------------------------------------
|
||||
void HudBarBaseCtrl::initPersistFields() {
|
||||
Parent::initPersistFields();
|
||||
|
||||
addField( "displayMounted", TypeBool, Offset( mDisplayMounted, HudBarBaseCtrl ) );
|
||||
addField( "pulseRate", TypeS32, Offset( mPulseRate, HudBarBaseCtrl ) );
|
||||
addField( "pulseThreshold", TypeF32, Offset( mPulseThreshold, HudBarBaseCtrl ) );
|
||||
addField( "verticalFill", TypeBool, Offset( mVerticalFill, HudBarBaseCtrl ) );
|
||||
addField( "subRegion", TypeRectI, Offset( mSubRegion, HudBarBaseCtrl ) );
|
||||
}
|
||||
|
||||
// hudBarBaseCtrl.cc
|
||||
66
hud/hudBarBaseCtrl.h
Normal file
66
hud/hudBarBaseCtrl.h
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hud/hudCtrl.h"
|
||||
#include "console/consoleTypes.h"
|
||||
#include "dgl/dgl.h"
|
||||
|
||||
//===========================================================================
|
||||
// CLASS: HudBarBaseCtrl
|
||||
//
|
||||
// This HUD object is a horizontal percentile bar
|
||||
//===========================================================================
|
||||
|
||||
class HudBarBaseCtrl : public HudCtrl {
|
||||
private:
|
||||
typedef HudCtrl Parent;
|
||||
|
||||
RectI mSubRegion;
|
||||
|
||||
protected:
|
||||
//------------------------------------------------------------------
|
||||
// getValue
|
||||
//
|
||||
// Default method that is intended to be over-ridden, returns
|
||||
// the current value of the bar in a percentile format
|
||||
//
|
||||
// Return: Value of the bar as a percentile
|
||||
//------------------------------------------------------------------
|
||||
virtual F32 getValue() {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// getBarColor
|
||||
//
|
||||
// This method stores the fill color of the bar in a provided variable
|
||||
//
|
||||
// col - This color variable will be set to the current fill color of the bar
|
||||
//------------------------------------------------------------------
|
||||
virtual void getBarColor( ColorI &col ) {
|
||||
col.set( mFillColor.red * 255, mFillColor.green * 255, mFillColor.blue * 255 );
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
HudBarBaseCtrl();
|
||||
|
||||
// GuiControl
|
||||
bool onWake();
|
||||
void onSleep();
|
||||
void onRender( Point2I, const RectI &, GuiControl * );
|
||||
|
||||
S32 mPulseRate;
|
||||
F32 mPulseThreshold;
|
||||
bool mVerticalFill;
|
||||
bool mPulse;
|
||||
bool mDisplayMounted;
|
||||
|
||||
static void initPersistFields();
|
||||
|
||||
DECLARE_CONOBJECT(HudBarBaseCtrl);
|
||||
};
|
||||
170
hud/hudBarDisplayCtrl.cc
Normal file
170
hud/hudBarDisplayCtrl.cc
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hud/hudBarDisplayCtrl.h"
|
||||
#include "hud/hudGLEx.h"
|
||||
|
||||
IMPLEMENT_CONOBJECT( HudBarDisplayCtrl );
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
HudBarDisplayCtrl::HudBarDisplayCtrl() {
|
||||
mPulseRate = 500;
|
||||
mPulseThreshold = 0.3f;
|
||||
mPulse = false;
|
||||
mHorizontalBar = true;
|
||||
mDrawFromOrigin = true;
|
||||
mShowPercentage = false;
|
||||
mDisplayMounted = false;
|
||||
mGradientFill = true;
|
||||
mValue = 0.2f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default method that is intended to be over-ridden, returns
|
||||
* the current value of the bar in a percentile format
|
||||
*
|
||||
* @return Value of the bar as a percentile
|
||||
*/
|
||||
F32 HudBarDisplayCtrl::getValue() {
|
||||
return mValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the color of the bar, this allows for
|
||||
* the changing of the bar color depending upon it's value
|
||||
* and things like that.
|
||||
*
|
||||
* @return Bar color
|
||||
*/
|
||||
ColorI HudBarDisplayCtrl::getBarColor() {
|
||||
return ColorI( 0, 255, 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the secondary color of the bar, this allows for
|
||||
* the changing of the bar color depending upon it's value
|
||||
* and things like that.
|
||||
*
|
||||
* @return Secondary bar color
|
||||
*/
|
||||
ColorI HudBarDisplayCtrl::getSecondBarColor() {
|
||||
return ColorI( 255, 0, 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called to render the HUD object
|
||||
*
|
||||
* @param offset Basically the corner to begin drawing at
|
||||
* @param updateRect The rectangle that this object updates
|
||||
* @param firstResponder ?
|
||||
*/
|
||||
void HudBarDisplayCtrl::onRender( Point2I offset,
|
||||
const RectI &updateRect,
|
||||
GuiControl * firstResponder ) {
|
||||
mFillColor.alpha = mOpacity;
|
||||
|
||||
F32 val = getValue();
|
||||
if( val > 1.0f )
|
||||
val = 1.0f;
|
||||
else if( val < 0.0f )
|
||||
val = 0.0f;
|
||||
|
||||
ColorI fill, fill2;
|
||||
fill = getBarColor();
|
||||
fill2 = getBarColor();
|
||||
|
||||
fill.alpha = mOpacity * 255;
|
||||
fill2.alpha = mOpacity * 255;
|
||||
|
||||
RectI rect( updateRect );
|
||||
|
||||
S32 modVal = ( mDrawFromOrigin ? -1 : 1 );
|
||||
|
||||
if( mHorizontalBar )
|
||||
if( mDrawFromOrigin )
|
||||
rect.extent.x *= val;
|
||||
else {
|
||||
rect.point.x += rect.extent.x * ( 1.0f - val );
|
||||
rect.extent.x *= val;
|
||||
}
|
||||
else
|
||||
if( mDrawFromOrigin )
|
||||
rect.extent.y *= val;
|
||||
else {
|
||||
rect.point.y += rect.extent.y * ( 1.0f - val );
|
||||
rect.extent.y *= val;
|
||||
rect.extent.y++; // Wierd, yeah, this is just to fix it being off by one pix from bottom
|
||||
}
|
||||
|
||||
if( mPulse && ( mPulseRate != 0 ) ) {
|
||||
S32 time = (S32)Platform::getVirtualMilliseconds();
|
||||
F32 alpha = F32( time % mPulseRate ) / F32( mPulseRate / 2 );
|
||||
|
||||
if( alpha > 1 )
|
||||
alpha = 1.f - ( alpha - 1.f );
|
||||
|
||||
fill.alpha *= alpha;
|
||||
fill.alpha *= 255;
|
||||
fill2.alpha *= alpha;
|
||||
fill2.alpha *= 255;
|
||||
}
|
||||
|
||||
if( mShowFill )
|
||||
dglDrawRectFill( updateRect, mFillColor );
|
||||
|
||||
if( mGradientFill ) {
|
||||
fill2 = getSecondBarColor();
|
||||
fill2.alpha = mOpacity * 255;
|
||||
}
|
||||
|
||||
if( !mHorizontalBar )
|
||||
if( !mDrawFromOrigin )
|
||||
dglDrawRectFill( rect, fill, fill2, fill, fill2 );
|
||||
else
|
||||
dglDrawRectFill( rect, fill2, fill, fill2, fill );
|
||||
else
|
||||
if( !mDrawFromOrigin )
|
||||
dglDrawRectFill( rect, fill, fill, fill2, fill2 );
|
||||
else
|
||||
dglDrawRectFill( rect, fill2, fill2, fill, fill );
|
||||
|
||||
if( mShowPercentage ) {
|
||||
char buf[256];
|
||||
S32 per = (S32)mFloor( val * 100.0f );
|
||||
|
||||
dSprintf( buf, sizeof( buf ), "%d%%", per );
|
||||
|
||||
offset.x += ( updateRect.extent.x / 2 ) - ( mProfile->mFont->getStrWidth( buf ) / 2 );
|
||||
offset.y += ( updateRect.extent.y / 2 ) - ( mProfile->mFont->getHeight() / 2 );
|
||||
|
||||
drawText( offset, buf );
|
||||
}
|
||||
|
||||
if( mShowFrame )
|
||||
dglDrawRect( updateRect, mFrameColor );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers console-modifyable datamembers
|
||||
*/
|
||||
void HudBarDisplayCtrl::initPersistFields() {
|
||||
Parent::initPersistFields();
|
||||
|
||||
addField( "pulse", TypeBool, Offset( mPulse, HudBarDisplayCtrl ) );
|
||||
addField( "horizontalBar", TypeBool, Offset( mHorizontalBar, HudBarDisplayCtrl ) );
|
||||
addField( "drawFromOrigin", TypeBool, Offset( mDrawFromOrigin, HudBarDisplayCtrl ) );
|
||||
addField( "showPercentage", TypeBool, Offset( mShowPercentage, HudBarDisplayCtrl ) );
|
||||
addField( "displayMounted", TypeBool, Offset( mDisplayMounted, HudBarDisplayCtrl ) );
|
||||
addField( "gradientFill", TypeBool, Offset( mGradientFill, HudBarDisplayCtrl ) );
|
||||
addField( "pulseRate", TypeS32, Offset( mPulseRate, HudBarDisplayCtrl ) );
|
||||
addField( "pulseThreshold", TypeF32, Offset( mPulseThreshold, HudBarDisplayCtrl ) );
|
||||
addField( "value", TypeF32, Offset( mValue, HudBarDisplayCtrl ) );
|
||||
}
|
||||
|
||||
// HudBarDisplayCtrl.cc
|
||||
50
hud/hudBarDisplayCtrl.h
Normal file
50
hud/hudBarDisplayCtrl.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _HUDBARDISPLAYCTRL_H_
|
||||
#define _HUDBARDISPLAYCTRL_H_
|
||||
|
||||
#include "hud/hudObject.h"
|
||||
#include "console/consoleTypes.h"
|
||||
|
||||
/**
|
||||
* This is a HUD object that displays data in horizontal or vertical
|
||||
* percentage bars
|
||||
*/
|
||||
class HudBarDisplayCtrl : public HudObject {
|
||||
private:
|
||||
typedef HudObject Parent;
|
||||
|
||||
protected:
|
||||
virtual F32 getValue();
|
||||
virtual ColorI getBarColor();
|
||||
virtual ColorI getSecondBarColor();
|
||||
|
||||
public:
|
||||
|
||||
HudBarDisplayCtrl();
|
||||
|
||||
void onRender( Point2I, const RectI &, GuiControl * );
|
||||
|
||||
S32 mPulseRate;
|
||||
F32 mPulseThreshold;
|
||||
bool mPulse;
|
||||
bool mHorizontalBar;
|
||||
bool mDrawFromOrigin;
|
||||
bool mShowPercentage;
|
||||
bool mDisplayMounted;
|
||||
bool mGradientFill;
|
||||
F32 mValue;
|
||||
|
||||
static void initPersistFields();
|
||||
|
||||
DECLARE_CONOBJECT( HudBarDisplayCtrl );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// HudBarDisplayCtrl.h
|
||||
179
hud/hudBezierDisplayCtrl.cc
Normal file
179
hud/hudBezierDisplayCtrl.cc
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hud/hudBezierDisplayCtrl.h"
|
||||
#include "hud/hudGLEx.h"
|
||||
|
||||
IMPLEMENT_CONOBJECT( HudBezierDisplayCtrl );
|
||||
|
||||
HudBezierDisplayCtrl::HudBezierDisplayCtrl() {
|
||||
mCurve = NULL;
|
||||
|
||||
mPulseRate = 500;
|
||||
mPulseThreshold = 0.3f;
|
||||
mPulse = false;
|
||||
mDrawFromOrigin = true;
|
||||
mShowPercentage = false;
|
||||
mDisplayMounted = false;
|
||||
mGradientFill = true;
|
||||
mValue = 0.2f;
|
||||
|
||||
mOffset.set( 0, 0 );
|
||||
mTextOffset.set( 0, 0 );
|
||||
mScaleValue = 0.4f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
HudBezierDisplayCtrl::~HudBezierDisplayCtrl() {
|
||||
if( mCurve != NULL )
|
||||
delete mCurve;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default method that is intended to be over-ridden, returns
|
||||
* the current value of the bar in a percentile format
|
||||
*
|
||||
* @return Value of the bar as a percentile
|
||||
*/
|
||||
F32 HudBezierDisplayCtrl::getValue() {
|
||||
return mValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the color of the bar, this allows for
|
||||
* the changing of the bar color depending upon it's value
|
||||
* and things like that.
|
||||
*
|
||||
* @return Bar color
|
||||
*/
|
||||
ColorI HudBezierDisplayCtrl::getBarColor() {
|
||||
return ColorI( 0, 255, 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the secondary color of the bar, this allows for
|
||||
* the changing of the bar color depending upon it's value
|
||||
* and things like that.
|
||||
*
|
||||
* @return Secondary bar color
|
||||
*/
|
||||
ColorI HudBezierDisplayCtrl::getSecondBarColor() {
|
||||
return ColorI( 255, 0, 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets executed whenever the control is resized
|
||||
*
|
||||
* @param newPosition The new position of the top left corner of the control
|
||||
* @param newExtent The new extent of the control
|
||||
*/
|
||||
void HudBezierDisplayCtrl::resize( const Point2I &newPosition, const Point2I &newExtent ) {
|
||||
Parent::resize( newPosition, newExtent );
|
||||
|
||||
Point2F ctrlPoints[4];
|
||||
Point2I upperL, lowerR;
|
||||
|
||||
upperL.set( mBounds.point.x, mBounds.point.y );
|
||||
lowerR.set( mBounds.point.x + mBounds.extent.x - 1, mBounds.point.y + mBounds.extent.y - 1 );
|
||||
|
||||
ctrlPoints[0].set( upperL.x, lowerR.y );
|
||||
ctrlPoints[1].set( upperL.x, upperL.y );
|
||||
ctrlPoints[2].set( lowerR.x, upperL.y );
|
||||
ctrlPoints[3].set( lowerR.x, lowerR.y + 10 );
|
||||
|
||||
if( mCurve == NULL )
|
||||
mCurve = new Bezier2D( ctrlPoints, 4, 49 );
|
||||
else
|
||||
mCurve->setControlPoints( ctrlPoints, 4 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called to render the HUD object
|
||||
*
|
||||
* @param offset Basically the corner to begin drawing at
|
||||
* @param updateRect The rectangle that this object updates
|
||||
* @param firstResponder ?
|
||||
*/
|
||||
void HudBezierDisplayCtrl::onRender( Point2I offset, const RectI &updateRect, GuiControl *firstResponder ) {
|
||||
if( mCurve != NULL ) {
|
||||
mFillColor.alpha = mOpacity;
|
||||
|
||||
ColorI fill = getBarColor();
|
||||
ColorI fill2 = getSecondBarColor();
|
||||
|
||||
if( mPulse && ( mPulseRate != 0 ) ) {
|
||||
S32 time = (S32)Platform::getVirtualMilliseconds();
|
||||
F32 alpha = F32( time % mPulseRate ) / F32( mPulseRate / 2 );
|
||||
|
||||
if( alpha > 1 )
|
||||
alpha = 1.f - ( alpha - 1.f );
|
||||
|
||||
fill.alpha *= alpha;
|
||||
fill.alpha *= 255;
|
||||
fill2.alpha *= alpha;
|
||||
fill2.alpha *= 255;
|
||||
}
|
||||
|
||||
if( mShowFill )
|
||||
dglDrawBezierBand( mCurve, mOffset, mScaleValue, mFillColor );
|
||||
if( mGradientFill )
|
||||
dglDrawBezierBand( mCurve, mOffset, mScaleValue, fill, fill2, getValue(), !mDrawFromOrigin );
|
||||
else
|
||||
dglDrawBezierBand( mCurve, mOffset, mScaleValue, fill, getValue(), !mDrawFromOrigin );
|
||||
|
||||
if( mShowFrame ) {
|
||||
dglDrawBezier( mCurve, mFrameColor );
|
||||
dglDrawBezier( mCurve->getScaledCurve( mScaleValue ), mFrameColor, mOffset );
|
||||
|
||||
Point2I pt1( mCurve->getScaledCurve( mScaleValue )->getCurvePoints()[0].x + mOffset.x,
|
||||
mCurve->getScaledCurve( mScaleValue )->getCurvePoints()[0].y - mOffset.y );
|
||||
Point2I pt2( mCurve->getCurvePoints()[0].x, mCurve->getCurvePoints()[0].y );
|
||||
dglDrawLine( pt1, pt2, mFrameColor );
|
||||
|
||||
pt1.set( mCurve->getScaledCurve( mScaleValue )->getCurvePoints()[mCurve->getNumCurvePoints() - 1].x + mOffset.x,
|
||||
mCurve->getScaledCurve( mScaleValue )->getCurvePoints()[mCurve->getNumCurvePoints() - 1].y - mOffset.y );
|
||||
pt2.set( mCurve->getCurvePoints()[mCurve->getNumCurvePoints() - 1].x,
|
||||
mCurve->getCurvePoints()[mCurve->getNumCurvePoints() - 1].y );
|
||||
dglDrawLine( pt1, pt2, mFrameColor );
|
||||
}
|
||||
|
||||
if( mShowPercentage ) {
|
||||
char buf[256];
|
||||
S32 per = (S32)mFloor( getValue() * 100.0f );
|
||||
|
||||
dSprintf( buf, sizeof( buf ), "%d%%", per );
|
||||
|
||||
drawText( Point2I( offset.x + mTextOffset.x - ( mProfile->mFont->getStrWidth( buf ) / 2 ),
|
||||
offset.y + mTextOffset.y - ( mProfile->mFont->getHeight() / 2 ) ), buf );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers console-modifyable datamembers
|
||||
*/
|
||||
void HudBezierDisplayCtrl::initPersistFields() {
|
||||
Parent::initPersistFields();
|
||||
|
||||
addField( "pulse", TypeBool, Offset( mPulse, HudBezierDisplayCtrl ) );
|
||||
addField( "drawFromOrigin", TypeBool, Offset( mDrawFromOrigin, HudBezierDisplayCtrl ) );
|
||||
addField( "showPercentage", TypeBool, Offset( mShowPercentage, HudBezierDisplayCtrl ) );
|
||||
addField( "displayMounted", TypeBool, Offset( mDisplayMounted, HudBezierDisplayCtrl ) );
|
||||
addField( "gradientFill", TypeBool, Offset( mGradientFill, HudBezierDisplayCtrl ) );
|
||||
addField( "pulseRate", TypeS32, Offset( mPulseRate, HudBezierDisplayCtrl ) );
|
||||
addField( "pulseThreshold", TypeF32, Offset( mPulseThreshold, HudBezierDisplayCtrl ) );
|
||||
addField( "value", TypeF32, Offset( mValue, HudBezierDisplayCtrl ) );
|
||||
addField( "offsetX", TypeF32, Offset( mOffset.x, HudBezierDisplayCtrl ) );
|
||||
addField( "offsetY", TypeF32, Offset( mOffset.y, HudBezierDisplayCtrl ) );
|
||||
addField( "textOffsetX", TypeF32, Offset( mTextOffset.x, HudBezierDisplayCtrl ) );
|
||||
addField( "textOffsetY", TypeF32, Offset( mTextOffset.y, HudBezierDisplayCtrl ) );
|
||||
addField( "scaleValue", TypeF32, Offset( mScaleValue, HudBezierDisplayCtrl ) );
|
||||
}
|
||||
|
||||
// hudBezierDisplayCtrl.cc
|
||||
50
hud/hudBezierDisplayCtrl.h
Normal file
50
hud/hudBezierDisplayCtrl.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _HUDBEZIERDISPLAYCTRL_H_
|
||||
#define _HUDBEZIERDISPLAYCTRL_H_
|
||||
|
||||
#include "hud/hudObject.h"
|
||||
#include "math/mBezier2D.h"
|
||||
#include "console/consoleTypes.h"
|
||||
|
||||
class HudBezierDisplayCtrl : public HudObject {
|
||||
private:
|
||||
typedef HudObject Parent;
|
||||
|
||||
Bezier2D *mCurve;
|
||||
|
||||
protected:
|
||||
virtual F32 getValue();
|
||||
virtual ColorI getBarColor();
|
||||
virtual ColorI getSecondBarColor();
|
||||
|
||||
public:
|
||||
HudBezierDisplayCtrl();
|
||||
~HudBezierDisplayCtrl();
|
||||
void resize( const Point2I &newPosition, const Point2I &newExtent );
|
||||
void onRender( Point2I, const RectI &, GuiControl * );
|
||||
|
||||
S32 mPulseRate;
|
||||
F32 mPulseThreshold;
|
||||
bool mPulse;
|
||||
bool mDrawFromOrigin;
|
||||
bool mShowPercentage;
|
||||
bool mDisplayMounted;
|
||||
bool mGradientFill;
|
||||
F32 mValue;
|
||||
Point2F mOffset, mTextOffset;
|
||||
F32 mScaleValue;
|
||||
|
||||
static void initPersistFields();
|
||||
|
||||
DECLARE_CONOBJECT( HudBezierDisplayCtrl );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// hudBezierDisplayCtrl.h
|
||||
121
hud/hudBitmapCtrl.cc
Normal file
121
hud/hudBitmapCtrl.cc
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hud/hudBitmapCtrl.h"
|
||||
|
||||
IMPLEMENT_CONOBJECT(HudBitmapCtrl);
|
||||
|
||||
HudBitmapCtrl::HudBitmapCtrl()
|
||||
{
|
||||
mBitmapHandle = 0;
|
||||
|
||||
//
|
||||
mBitmap = 0;
|
||||
mAutoResize = false;
|
||||
mAutoCenter = false;
|
||||
mFlipVert = false;
|
||||
mFlipHorz = false;
|
||||
}
|
||||
|
||||
void HudBitmapCtrl::setBitmap(const char * bitmap)
|
||||
{
|
||||
mBitmap = StringTable->insert(bitmap);
|
||||
mBitmapHandle = TextureHandle(mBitmap, BitmapTexture);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void HudBitmapCtrl::onPreRender()
|
||||
{
|
||||
GuiControl * parent = getParent();
|
||||
if(!parent)
|
||||
return;
|
||||
|
||||
// set extent to that of bitmap
|
||||
if(mAutoResize && bool(mBitmapHandle))
|
||||
{
|
||||
Point2I dim(mBitmapHandle.getWidth(), mBitmapHandle.getHeight());
|
||||
if (dim != getExtent())
|
||||
resize(getPosition(), dim);
|
||||
}
|
||||
|
||||
// resize to parent
|
||||
if(mAutoCenter)
|
||||
{
|
||||
Point2I pos = parent->getExtent();
|
||||
pos = pos / 2 - (getExtent() + Point2I(1,1)) / 2;
|
||||
resize(pos, getExtent());
|
||||
}
|
||||
|
||||
Parent::onPreRender();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void HudBitmapCtrl::onRender(Point2I offset, const RectI & updateRect, GuiControl * firstResponder)
|
||||
{
|
||||
if(!bool(mBitmapHandle))
|
||||
{
|
||||
Parent::onRender(offset, updateRect, firstResponder);
|
||||
return;
|
||||
}
|
||||
|
||||
U32 flip = ( mFlipVert ? GFlip_Y : GFlip_None ) | ( mFlipHorz ? GFlip_X : GFlip_None );
|
||||
|
||||
mOpacity = mClampF(mOpacity, 0.f, 1.f);
|
||||
|
||||
//
|
||||
dglSetBitmapModulation(ColorF(1,1,1,mOpacity));
|
||||
dglDrawBitmapStretch(mBitmapHandle, updateRect, flip);
|
||||
dglClearBitmapModulation();
|
||||
|
||||
renderChildControls(offset, updateRect, firstResponder);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void HudBitmapCtrl::inspectPostApply()
|
||||
{
|
||||
mBitmapHandle = TextureHandle(mBitmap, BitmapTexture);
|
||||
Parent::inspectPostApply();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool HudBitmapCtrl::onWake()
|
||||
{
|
||||
if(!Parent::onWake())
|
||||
return(false);
|
||||
mBitmapHandle = TextureHandle(mBitmap, BitmapTexture);
|
||||
return(true);
|
||||
}
|
||||
|
||||
void HudBitmapCtrl::onSleep()
|
||||
{
|
||||
mBitmapHandle = 0;
|
||||
Parent::onSleep();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void HudBitmapCtrl::initPersistFields()
|
||||
{
|
||||
Parent::initPersistFields();
|
||||
addField("bitmap", TypeString, Offset(mBitmap, HudBitmapCtrl));
|
||||
addField("autoCenter", TypeBool, Offset(mAutoCenter, HudBitmapCtrl));
|
||||
addField("autoResize", TypeBool, Offset(mAutoResize, HudBitmapCtrl));
|
||||
addField("flipVertical", TypeBool, Offset(mFlipVert, HudBitmapCtrl));
|
||||
addField("flipHorizontal", TypeBool, Offset(mFlipHorz, HudBitmapCtrl));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
ConsoleMethod( HudBitmapCtrl, setBitmap, void, 3, 3, "hudBitmapCtrl.setBitmap( bitmap )" )
|
||||
{
|
||||
argc;
|
||||
static_cast<HudBitmapCtrl*>( object )->setBitmap( argv[2] );
|
||||
}
|
||||
58
hud/hudBitmapCtrl.h
Normal file
58
hud/hudBitmapCtrl.h
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _HUDBITMAPCTRL_H_
|
||||
#define _HUDBITMAPCTRL_H_
|
||||
|
||||
#ifndef _HUDCTRL_H_
|
||||
#include "hud/hudCtrl.h"
|
||||
#endif
|
||||
#ifndef _CONSOLETYPES_H_
|
||||
#include "console/consoleTypes.h"
|
||||
#endif
|
||||
#ifndef _DGL_H_
|
||||
#include "dgl/dgl.h"
|
||||
#endif
|
||||
|
||||
class HudBitmapCtrl : public HudCtrl
|
||||
{
|
||||
private:
|
||||
typedef HudCtrl Parent;
|
||||
|
||||
protected:
|
||||
|
||||
TextureHandle mBitmapHandle;
|
||||
|
||||
public:
|
||||
|
||||
HudBitmapCtrl();
|
||||
|
||||
void setBitmap(const char * bitmap);
|
||||
|
||||
// SimObject
|
||||
void inspectPostApply();
|
||||
|
||||
// GuiControl
|
||||
void onPreRender();
|
||||
void onRender(Point2I offset, const RectI & updateRect, GuiControl * firstResponder);
|
||||
|
||||
bool onWake();
|
||||
void onSleep();
|
||||
|
||||
// field data
|
||||
StringTableEntry mBitmap;
|
||||
bool mAutoResize;
|
||||
bool mAutoCenter;
|
||||
bool mFlipVert;
|
||||
bool mFlipHorz;
|
||||
|
||||
static void initPersistFields();
|
||||
|
||||
DECLARE_CONOBJECT(HudBitmapCtrl);
|
||||
};
|
||||
|
||||
#endif
|
||||
31
hud/hudBitmapFrameCtrl.cc
Normal file
31
hud/hudBitmapFrameCtrl.cc
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hud/hudBitmapFrameCtrl.h"
|
||||
|
||||
IMPLEMENT_CONOBJECT(HudBitmapFrameCtrl);
|
||||
|
||||
HudBitmapFrameCtrl::HudBitmapFrameCtrl()
|
||||
{
|
||||
mSubRegion.set(0,0,1,1);
|
||||
}
|
||||
|
||||
void HudBitmapFrameCtrl::onPreRender()
|
||||
{
|
||||
if (mAutoResize && bool(mBitmapHandle))
|
||||
{
|
||||
Point2I dim(mBitmapHandle.getWidth(), mBitmapHandle.getHeight());
|
||||
if (dim != getExtent())
|
||||
resize(getPosition(), dim);
|
||||
}
|
||||
}
|
||||
|
||||
void HudBitmapFrameCtrl::initPersistFields()
|
||||
{
|
||||
Parent::initPersistFields();
|
||||
addField("subRegion", TypeRectI, Offset(mSubRegion, HudBitmapFrameCtrl));
|
||||
}
|
||||
35
hud/hudBitmapFrameCtrl.h
Normal file
35
hud/hudBitmapFrameCtrl.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _HUDBITMAPFRAMECTRL_H_
|
||||
#define _HUDBITMAPFRAMECTRL_H_
|
||||
|
||||
#ifndef _HUDBITMAPCTRL_H_
|
||||
#include "hud/hudBitmapCtrl.h"
|
||||
#endif
|
||||
|
||||
class HudBitmapFrameCtrl : public HudBitmapCtrl
|
||||
{
|
||||
private:
|
||||
typedef HudBitmapCtrl Parent;
|
||||
|
||||
public:
|
||||
|
||||
HudBitmapFrameCtrl();
|
||||
|
||||
// GuiControl
|
||||
void onPreRender();
|
||||
|
||||
// field data
|
||||
RectI mSubRegion;
|
||||
|
||||
static void initPersistFields();
|
||||
|
||||
DECLARE_CONOBJECT(HudBitmapFrameCtrl);
|
||||
};
|
||||
|
||||
#endif
|
||||
104
hud/hudClock.cc
Normal file
104
hud/hudClock.cc
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hud/hudBitmapFrameCtrl.h"
|
||||
#include "dgl/dgl.h"
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// CLASS: HudClockCtrl
|
||||
//---------------------------------------------------------------------------
|
||||
class HudClockCtrl : public HudBitmapFrameCtrl
|
||||
{
|
||||
private:
|
||||
|
||||
typedef HudBitmapFrameCtrl Parent;
|
||||
S32 mCurrentSetTime;
|
||||
|
||||
public:
|
||||
|
||||
HudClockCtrl();
|
||||
|
||||
void setTime(F32);
|
||||
static void consoleInit();
|
||||
|
||||
void onRender(Point2I offset, const RectI &updateRect, GuiControl *firstResponder);
|
||||
DECLARE_CONOBJECT(HudClockCtrl);
|
||||
};
|
||||
|
||||
IMPLEMENT_CONOBJECT(HudClockCtrl);
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
HudClockCtrl::HudClockCtrl()
|
||||
{
|
||||
mCurrentSetTime = 0;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void HudClockCtrl::setTime(F32 newTime)
|
||||
{
|
||||
F32 time = Platform::getVirtualMilliseconds();
|
||||
mCurrentSetTime = -(S32)((newTime*60*1000)+time);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void HudClockCtrl::onRender(Point2I /*offset*/,
|
||||
const RectI& /*updateRect*/,
|
||||
GuiControl* /*firstResponder*/)
|
||||
{
|
||||
// Parent::onRender(offset, updateRect, firstResponder);
|
||||
|
||||
char buf[256];
|
||||
Point2I localStart;
|
||||
S32 secondsLeft, hours, mins, secs, hundredths;
|
||||
|
||||
F32 actualTimeMS = (F32)mCurrentSetTime + Platform::getVirtualMilliseconds();
|
||||
F32 time = mAbs(actualTimeMS);
|
||||
|
||||
secondsLeft = (S32)time/1000;
|
||||
hundredths = (S32)((time - (secondsLeft*1000))/10);
|
||||
hours = secondsLeft / 3600;
|
||||
secondsLeft -= hours * 3600;
|
||||
mins = secondsLeft / 60;
|
||||
secondsLeft -= mins * 60;
|
||||
secs = secondsLeft;
|
||||
|
||||
// dSprintf(buf, sizeof(buf), "%02d:%02d:%02d.%1d", hours, mins, secs, tenths);
|
||||
if (mins == 0 && actualTimeMS < 0)
|
||||
dSprintf(buf, sizeof(buf), "%02d.%02d", secs, hundredths);
|
||||
else
|
||||
dSprintf(buf, sizeof(buf), "%02d:%02d", mins, secs);
|
||||
|
||||
localStart.x = (mSubRegion.extent.x - mProfile->mFont->getStrWidth(buf)) / 2;
|
||||
localStart.y = ((mSubRegion.extent.y - (mProfile->mFont->getHeight() - 2)) / 2);
|
||||
localStart += mSubRegion.point;
|
||||
|
||||
//
|
||||
if(localStart.x < 0)
|
||||
localStart.x = mSubRegion.point.x;
|
||||
if(localStart.y < 0)
|
||||
localStart.y = mSubRegion.point.y;
|
||||
|
||||
dglSetBitmapModulation(ColorF(1,1,1,mOpacity));
|
||||
dglDrawText(mProfile->mFont, localToGlobalCoord(localStart), buf);
|
||||
dglClearBitmapModulation();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
static void cHudClockCtrlSetTime(SimObject *obj, S32, const char **argv)
|
||||
{
|
||||
HudClockCtrl *ctrl = static_cast<HudClockCtrl*>(obj);
|
||||
ctrl->setTime(dAtof(argv[2]));
|
||||
}
|
||||
|
||||
void HudClockCtrl::consoleInit()
|
||||
{
|
||||
Con::addCommand("hudClock", "setTime", cHudClockCtrlSetTime, "timer.setTime(Time In Min's)", 3, 3);
|
||||
}
|
||||
116
hud/hudClockCtrl.cc
Normal file
116
hud/hudClockCtrl.cc
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hud/hudObject.h"
|
||||
#include "hud/hudGLEx.h"
|
||||
#include "console/consoleTypes.h"
|
||||
|
||||
/**
|
||||
* HudClock is a clock for the HUD.
|
||||
*/
|
||||
class HudClockCtrl : public HudObject {
|
||||
|
||||
private:
|
||||
typedef HudObject Parent;
|
||||
S32 mStoredTime;
|
||||
|
||||
public:
|
||||
HudClockCtrl();
|
||||
|
||||
void setTime( F32 newTime );
|
||||
static void consoleInit();
|
||||
|
||||
void onRender( Point2I offset, const RectI &updateRect, GuiControl *firstResponder );
|
||||
|
||||
DECLARE_CONOBJECT( HudClockCtrl );
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
IMPLEMENT_CONOBJECT( HudClockCtrl );
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
HudClockCtrl::HudClockCtrl() {
|
||||
mStoredTime = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to set the ammount of time this clock should display.
|
||||
*
|
||||
* @param newTime Time to display in minutes
|
||||
*/
|
||||
void HudClockCtrl::setTime( F32 newTime ) {
|
||||
F32 time = Platform::getVirtualMilliseconds();
|
||||
mStoredTime = -(S32)( ( newTime * 60 * 1000 )+ time );
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called to render the HUD object
|
||||
*
|
||||
* @param offset Basically the corner to begin drawing at
|
||||
* @param updateRect The rectangle that this object has power to draw in
|
||||
* @param firstResponder ?
|
||||
*/
|
||||
void HudClockCtrl::onRender( Point2I offset,
|
||||
const RectI &updateRect,
|
||||
GuiControl* firstResponder ) {
|
||||
|
||||
// Sanity check
|
||||
GuiControl *parent = getParent();
|
||||
if( !parent )
|
||||
return;
|
||||
|
||||
Parent::onRender( offset, updateRect, firstResponder );
|
||||
|
||||
// Declarations
|
||||
char buf[256];
|
||||
S32 hours, mins, secs, hundredths;
|
||||
|
||||
F32 actualTimeMS = (F32)mStoredTime + Platform::getVirtualMilliseconds();
|
||||
F32 time = mAbs( actualTimeMS );
|
||||
|
||||
// Operations
|
||||
secs = (S32)time / 1000;
|
||||
hundredths = (S32)( ( time - ( secs * 1000 ) ) / 10 );
|
||||
hours = secs / 3600;
|
||||
secs -= hours * 3600;
|
||||
mins = secs / 60;
|
||||
secs -= mins * 60;
|
||||
|
||||
if( mins == 0 && actualTimeMS < 0 )
|
||||
dSprintf( buf, sizeof( buf ), "%02d.%02d", secs, hundredths );
|
||||
else
|
||||
dSprintf( buf, sizeof( buf ), "%02d:%02d", mins, secs );
|
||||
|
||||
offset.x += ( mBounds.extent.x / 2 ) - ( mProfile->mFont->getStrWidth( buf ) / 2 );
|
||||
offset.y += ( mBounds.extent.y / 2 ) - ( mProfile->mFont->getHeight() / 2 );
|
||||
|
||||
drawText( offset, buf );
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from the console as a accessor to the setTime method
|
||||
*
|
||||
* @param obj Clock to set the time of, as this is a static method
|
||||
* @param argv Array of string arguments from console
|
||||
*/
|
||||
static void cHudClockCtrlSetTime( SimObject *obj, S32, const char **argv ) {
|
||||
HudClockCtrl *ctrl = static_cast<HudClockCtrl*>( obj );
|
||||
ctrl->setTime( dAtof( argv[2] ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds to the console the methods this object supports
|
||||
*/
|
||||
void HudClockCtrl::consoleInit() {
|
||||
Con::addCommand( "HudClockCtrl", "setTime", cHudClockCtrlSetTime, "timer.setTime(Time In Min's)", 3, 3 );
|
||||
}
|
||||
|
||||
// hudClockCtrl.cc
|
||||
194
hud/hudCompass.cc
Normal file
194
hud/hudCompass.cc
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hud/hudCtrl.h"
|
||||
#include "dgl/dgl.h"
|
||||
#include "gui/guiTSControl.h"
|
||||
#include "console/consoleTypes.h"
|
||||
#include "game/gameConnection.h"
|
||||
#include "game/camera.h"
|
||||
#include "dgl/gTexManager.h"
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Class: HudCompassCtrl
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class HudCompassCtrl : public HudCtrl
|
||||
{
|
||||
private:
|
||||
|
||||
typedef HudCtrl Parent;
|
||||
|
||||
public:
|
||||
|
||||
HudCompassCtrl();
|
||||
~HudCompassCtrl();
|
||||
|
||||
// SimBase
|
||||
bool onAdd();
|
||||
|
||||
// GuiControl
|
||||
void onPreRender();
|
||||
void onRender(Point2I, const RectI &, GuiControl *);
|
||||
bool onWake();
|
||||
void onSleep();
|
||||
|
||||
ColorI mTextColor;
|
||||
|
||||
static void initPersistFields();
|
||||
|
||||
DECLARE_CONOBJECT(HudCompassCtrl);
|
||||
};
|
||||
|
||||
IMPLEMENT_CONOBJECT(HudCompassCtrl);
|
||||
|
||||
HudCompassCtrl::HudCompassCtrl()
|
||||
{
|
||||
mTextColor.set( 0, 255, 0 );
|
||||
}
|
||||
|
||||
HudCompassCtrl::~HudCompassCtrl()
|
||||
{
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool HudCompassCtrl::onAdd()
|
||||
{
|
||||
if(!Parent::onAdd())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool HudCompassCtrl::onWake()
|
||||
{
|
||||
if(!Parent::onWake())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void HudCompassCtrl::onSleep()
|
||||
{
|
||||
Parent::onSleep();
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void HudCompassCtrl::onPreRender()
|
||||
{
|
||||
GuiControl * parent = getParent();
|
||||
if(!parent)
|
||||
return;
|
||||
|
||||
setUpdate();
|
||||
}
|
||||
|
||||
static float gCompassPoints[] =
|
||||
{
|
||||
//'N'
|
||||
4.0f, -2.0f, -28.0f, -2.0f, -34.0f, 2.0f, -28.0f, 2.0f, -34.0f,
|
||||
|
||||
//'E'
|
||||
4.0f, 28.0f, 2.0f, 28.0f, -2.0f, 34.0f, -2.0f, 34.0f, 2.0f,
|
||||
2.0f, 31.0f, -2.0f, 31.0f, 2.0f,
|
||||
|
||||
//'W'
|
||||
5.0f, -34.0f, 4.0f, -28.0f, 2.0f, -34.0f, 0.0f, -28.0f, -2.0f, -34.0f, -4.0f,
|
||||
|
||||
//'S'
|
||||
12.0f, 2.0f, 30.0f, 1.0f, 29.0f, -1.0f, 29.0f, -2.0f, 30.0f, -2.0f, 31.0f, -1.0f, 32.0f,
|
||||
1.0f, 32.0f, 2.0f, 33.0f, 2.0f, 34.0f, 1.0f, 35.0f, -1.0f, 35.0f, -2.0f, 34.0f,
|
||||
|
||||
//4 marks
|
||||
2.0f, 25.0f, -24.0f, 29.0f, -28.0f,
|
||||
2.0f, 25.0f, 24.0f, 29.0f, 28.0f,
|
||||
2.0f, -24.0f, 24.0f, -28.0f, 28.0f,
|
||||
2.0f, -24.0f, -24.0f, -28.0f, -28.0f,
|
||||
|
||||
//EOF
|
||||
-1.0f
|
||||
};
|
||||
|
||||
void HudCompassCtrl::onRender(Point2I offset, const RectI &, GuiControl *)
|
||||
{
|
||||
GameConnection * con = GameConnection::getServerConnection();
|
||||
if( !con )
|
||||
return;
|
||||
|
||||
ShapeBase *obj = con->getControlObject();
|
||||
|
||||
if( !obj )
|
||||
return;
|
||||
|
||||
Point2F centerPt;
|
||||
centerPt.x = 40.5f + F32( offset.x );
|
||||
centerPt.y = 38.5f + F32( offset.y );
|
||||
|
||||
MatrixF camMat;
|
||||
F32 camPos = 0;
|
||||
Point3F camVec;
|
||||
obj->getCameraTransform(&camPos, &camMat);
|
||||
|
||||
camMat.getColumn( 1, &camVec );
|
||||
camVec.z = 0.f;
|
||||
camVec.normalize();
|
||||
|
||||
F32 camAngle;
|
||||
F32 dot = mDot( camVec, Point3F( 0, 1, 0 ) );
|
||||
camAngle = mAcos( dot );
|
||||
|
||||
if(camVec.x > 0.f)
|
||||
camAngle = M_2PI - camAngle;
|
||||
|
||||
//rotate the needle around the compass
|
||||
F32 cosTheta, sinTheta;
|
||||
mSinCos( camAngle, sinTheta, cosTheta);
|
||||
|
||||
//loop through and rotate the compass markings
|
||||
Point2F markPoints[12];
|
||||
F32 *points;
|
||||
points = &gCompassPoints[0];
|
||||
|
||||
while( *points > 0.0f )
|
||||
{
|
||||
S32 j;
|
||||
for( j = 0; j < *points; j++ )
|
||||
{
|
||||
markPoints[j].x = (points[2 * j + 1] * cosTheta) - (points[2 * j + 2] * sinTheta);
|
||||
markPoints[j].y = (points[2 * j + 1] * sinTheta) + (points[2 * j + 2] * cosTheta);
|
||||
}
|
||||
|
||||
//now draw the lines
|
||||
for( j = 0; j < *points - 1; j++ )
|
||||
{
|
||||
Point2I tempStart;
|
||||
tempStart.x = S32( markPoints[j].x + centerPt.x );
|
||||
tempStart.y = S32( markPoints[j].y + centerPt.y );
|
||||
Point2I tempEnd;
|
||||
tempEnd.x = S32( markPoints[j + 1].x + centerPt.x );
|
||||
tempEnd.y = S32( markPoints[j + 1].y + centerPt.y );
|
||||
dglDrawLine( tempStart, tempEnd, ColorI(mTextColor.red, mTextColor.green, mTextColor.blue ) );
|
||||
}
|
||||
|
||||
//now increment the points pointer
|
||||
points += ( S32( *points ) * 2 ) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void HudCompassCtrl::initPersistFields()
|
||||
{
|
||||
Parent::initPersistFields();
|
||||
|
||||
addField("textColor", TypeColorI, Offset(mTextColor, HudCompassCtrl));
|
||||
}
|
||||
63
hud/hudCrosshair.cc
Normal file
63
hud/hudCrosshair.cc
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "gui/guiCanvas.h"
|
||||
#include "hud/hudBitmapCtrl.h"
|
||||
#include "game/gameConnection.h"
|
||||
#include "game/camera.h"
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Class: HudCrosshairCtrl
|
||||
//---------------------------------------------------------------------------
|
||||
class HudCrosshairCtrl : public HudBitmapCtrl
|
||||
{
|
||||
private:
|
||||
typedef HudBitmapCtrl Parent;
|
||||
|
||||
public:
|
||||
HudCrosshairCtrl();
|
||||
|
||||
// GuiControl
|
||||
void onRender(Point2I, const RectI &, GuiControl *);
|
||||
|
||||
DECLARE_CONOBJECT(HudCrosshairCtrl);
|
||||
};
|
||||
|
||||
IMPLEMENT_CONOBJECT(HudCrosshairCtrl);
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
HudCrosshairCtrl::HudCrosshairCtrl()
|
||||
{
|
||||
mAutoResize = true;
|
||||
mAutoCenter = true;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void HudCrosshairCtrl::onRender(Point2I offset, const RectI & updateRect, GuiControl * firstResponder)
|
||||
{
|
||||
if(!bool(mBitmapHandle))
|
||||
return;
|
||||
|
||||
// renders in center of parent control
|
||||
GuiControl * parent = getParent();
|
||||
if(!parent)
|
||||
return;
|
||||
|
||||
GameConnection * con = GameConnection::getServerConnection();
|
||||
if(!con)
|
||||
return;
|
||||
|
||||
if(!con->isFirstPerson())
|
||||
return;
|
||||
|
||||
if(dynamic_cast<Camera*>(con->getControlObject()))
|
||||
return;
|
||||
|
||||
Parent::onRender(offset, updateRect, firstResponder);
|
||||
}
|
||||
42
hud/hudCtrl.cc
Normal file
42
hud/hudCtrl.cc
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hud/hudCtrl.h"
|
||||
#include "console/consoleTypes.h"
|
||||
#include "dgl/dgl.h"
|
||||
|
||||
IMPLEMENT_CONOBJECT(HudCtrl);
|
||||
|
||||
HudCtrl::HudCtrl()
|
||||
{
|
||||
mFillColor.set(0.25, 0.25, 0.25, 0.25);
|
||||
mFrameColor.set(0, 1, 0, 1);
|
||||
mOpacity = 1.f;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void HudCtrl::onRender(Point2I offset, const RectI &updateRect, GuiControl * firstResponder)
|
||||
{
|
||||
RectI ctrlRect(offset, mBounds.extent);
|
||||
|
||||
//
|
||||
mFillColor.alpha = mFrameColor.alpha = mOpacity;
|
||||
|
||||
dglDrawRectFill(ctrlRect, mFillColor);
|
||||
dglDrawRect(ctrlRect, mFrameColor);
|
||||
|
||||
renderChildControls(offset, updateRect, firstResponder);
|
||||
}
|
||||
|
||||
void HudCtrl::initPersistFields()
|
||||
{
|
||||
Parent::initPersistFields();
|
||||
addField("fillColor", TypeColorF, Offset(mFillColor, HudCtrl));
|
||||
addField("frameColor", TypeColorF, Offset(mFrameColor, HudCtrl));
|
||||
addField("opacity", TypeF32, Offset(mOpacity, HudCtrl));
|
||||
}
|
||||
37
hud/hudCtrl.h
Normal file
37
hud/hudCtrl.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _HUDCTRL_H_
|
||||
#define _HUDCTRL_H_
|
||||
|
||||
#ifndef _GUICONTROL_H_
|
||||
#include "GUI/guiControl.h"
|
||||
#endif
|
||||
|
||||
class HudCtrl : public GuiControl
|
||||
{
|
||||
private:
|
||||
typedef GuiControl Parent;
|
||||
|
||||
public:
|
||||
|
||||
HudCtrl();
|
||||
|
||||
// GuiControl
|
||||
virtual void onRender(Point2I offset, const RectI &updateRect, GuiControl *firstResponder);
|
||||
|
||||
// field data
|
||||
ColorF mFillColor;
|
||||
ColorF mFrameColor;
|
||||
F32 mOpacity;
|
||||
|
||||
static void initPersistFields();
|
||||
|
||||
DECLARE_CONOBJECT(HudCtrl);
|
||||
};
|
||||
|
||||
#endif
|
||||
102
hud/hudDamageCtrl.cc
Normal file
102
hud/hudDamageCtrl.cc
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hudBarBaseCtrl.h"
|
||||
#include "game/gameConnection.h"
|
||||
#include "game/shapeBase.h"
|
||||
#include "game/camera.h"
|
||||
|
||||
//===========================================================================
|
||||
// CLASS: HudDamageCtrl
|
||||
//===========================================================================
|
||||
|
||||
class HudDamageCtrl : public HudBarBaseCtrl {
|
||||
private:
|
||||
typedef HudBarBaseCtrl Parent;
|
||||
|
||||
public:
|
||||
|
||||
F32 getValue();
|
||||
void getBarColor( ColorI &col );
|
||||
|
||||
DECLARE_CONOBJECT( HudDamageCtrl );
|
||||
};
|
||||
|
||||
//===========================================================================
|
||||
// HudDamageCtrl Implementation
|
||||
//===========================================================================
|
||||
IMPLEMENT_CONOBJECT( HudDamageCtrl );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// getBarColor
|
||||
//
|
||||
// This method ovrrides the virtual method in hudBarBaseCtrl
|
||||
// the bar changes color depending on how much damage is taken
|
||||
//------------------------------------------------------------------
|
||||
void HudDamageCtrl::getBarColor( ColorI &col ) {
|
||||
F32 val = getValue();
|
||||
|
||||
if( val < 0.6 && val > 0.25)
|
||||
col.set( 255, 178, 0 );
|
||||
else if( val <= 0.25 )
|
||||
col.set( 255, 0, 0 );
|
||||
else
|
||||
col.set( mFillColor.red * 255, mFillColor.green * 255, mFillColor.blue * 255);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// getValue
|
||||
//
|
||||
// This method is overridden from hudBarBaseCtrl, it returns the
|
||||
// damage level of the player as a percentile
|
||||
//
|
||||
// Return: Damage level of the player as a percentile
|
||||
//------------------------------------------------------------------
|
||||
F32 HudDamageCtrl::getValue() {
|
||||
|
||||
GameConnection *con = GameConnection::getServerConnection();
|
||||
|
||||
// Sanity check connection to game.
|
||||
if( !con )
|
||||
return( 0.f );
|
||||
|
||||
ShapeBase *obj = con->getControlObject();
|
||||
|
||||
if( !obj )
|
||||
return (0.f);
|
||||
|
||||
mPulse = false;
|
||||
|
||||
// If we're in a floating camera view...
|
||||
if( dynamic_cast<Camera*>( con->getControlObject() ) )
|
||||
return( 0.f );
|
||||
|
||||
// Nope, we're either on a vehicle or running around
|
||||
F32 damage = 0.0f;
|
||||
|
||||
if( mDisplayMounted ) {
|
||||
ShapeBase * mount = obj->getObjectMount();
|
||||
|
||||
while( mount && mount->isMounted() )
|
||||
mount = mount->getObjectMount();
|
||||
|
||||
if( mount )
|
||||
damage = mClampF( 1.f - mount->getDamageValue(), 0.f, 1.f );
|
||||
else
|
||||
damage = 0.0f;
|
||||
}
|
||||
else
|
||||
damage = mClampF( 1.f - obj->getDamageValue(), 0.f, 1.f );
|
||||
|
||||
|
||||
if( damage < 0.25 )
|
||||
mPulse = true;
|
||||
|
||||
return damage ;
|
||||
}
|
||||
|
||||
// hudDamage.cc
|
||||
67
hud/hudEnergyCtrl.cc
Normal file
67
hud/hudEnergyCtrl.cc
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hudBarBaseCtrl.h"
|
||||
#include "game/gameConnection.h"
|
||||
#include "game/shapeBase.h"
|
||||
|
||||
//===========================================================================
|
||||
// CLASS: HudEnergyCtrl
|
||||
//
|
||||
// This object displays the players energy level in a bar format
|
||||
//===========================================================================
|
||||
|
||||
class HudEnergyCtrl : public HudBarBaseCtrl {
|
||||
private:
|
||||
typedef HudBarBaseCtrl Parent;
|
||||
|
||||
public:
|
||||
|
||||
F32 getValue();
|
||||
|
||||
DECLARE_CONOBJECT( HudEnergyCtrl );
|
||||
};
|
||||
|
||||
//===========================================================================
|
||||
// HudEnergyCtrl Implementation
|
||||
//===========================================================================
|
||||
IMPLEMENT_CONOBJECT( HudEnergyCtrl );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// getValue
|
||||
//
|
||||
// This method is overridden from hudBarBaseCtrl, it returns the
|
||||
// energy level of the player as a percentile
|
||||
//
|
||||
// Return: Energy level of the player as a percentile
|
||||
//------------------------------------------------------------------
|
||||
F32 HudEnergyCtrl::getValue() {
|
||||
GameConnection *con = GameConnection::getServerConnection();
|
||||
|
||||
if( !con )
|
||||
return(0.f);
|
||||
|
||||
ShapeBase *obj = con->getControlObject();
|
||||
if( !obj )
|
||||
return(0.f);
|
||||
|
||||
if( mDisplayMounted ) {
|
||||
ShapeBase *mount = obj->getObjectMount();
|
||||
|
||||
while( mount && mount->isMounted() )
|
||||
mount = mount->getObjectMount();
|
||||
|
||||
if( mount )
|
||||
return( mClampF( mount->getEnergyValue(), 0.f, 1.f ) );
|
||||
else
|
||||
return( 0.f );
|
||||
}
|
||||
else
|
||||
return mClampF( obj->getEnergyValue(), 0.f, 1.f );
|
||||
}
|
||||
|
||||
// hudEnergy.cc
|
||||
296
hud/hudEnergyDamage.cc
Normal file
296
hud/hudEnergyDamage.cc
Normal file
|
|
@ -0,0 +1,296 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hud/hudBitmapFrameCtrl.h"
|
||||
#include "core/dnet.h"
|
||||
#include "game/gameConnection.h"
|
||||
#include "game/shapeBase.h"
|
||||
#include "game/camera.h"
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Class: HudBarBaseCtrl
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class HudBarBaseCtrl : public HudBitmapFrameCtrl
|
||||
{
|
||||
private:
|
||||
typedef HudBitmapFrameCtrl Parent;
|
||||
|
||||
protected:
|
||||
|
||||
virtual F32 getValue() { return( 0.0f ); }
|
||||
virtual void getBarColor(ColorI &col){ col.set( mFillColor.red * 255, mFillColor.green * 255, mFillColor.blue * 255); }
|
||||
public:
|
||||
|
||||
HudBarBaseCtrl();
|
||||
|
||||
// GuiControl
|
||||
bool onWake();
|
||||
void onSleep();
|
||||
void onRender(Point2I, const RectI &, GuiControl *);
|
||||
|
||||
S32 mPulseRate;
|
||||
F32 mPulseThreshold;
|
||||
bool mVerticalFill;
|
||||
bool mPulse;
|
||||
bool mDisplayMounted;
|
||||
|
||||
static void initPersistFields();
|
||||
|
||||
DECLARE_CONOBJECT(HudBarBaseCtrl);
|
||||
};
|
||||
|
||||
IMPLEMENT_CONOBJECT(HudBarBaseCtrl);
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
HudBarBaseCtrl::HudBarBaseCtrl()
|
||||
{
|
||||
mPulseRate = 500;
|
||||
mPulseThreshold = 0.3f;
|
||||
mVerticalFill = false;
|
||||
mPulse = false;
|
||||
mDisplayMounted = false;
|
||||
}
|
||||
|
||||
bool HudBarBaseCtrl::onWake()
|
||||
{
|
||||
if(!Parent::onWake())
|
||||
return(false);
|
||||
return(true);
|
||||
}
|
||||
|
||||
void HudBarBaseCtrl::onSleep()
|
||||
{
|
||||
Parent::onSleep();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void HudBarBaseCtrl::onRender(Point2I offset, const RectI & /*updateRect*/, GuiControl * /*firstResponder*/)
|
||||
{
|
||||
GameConnection * con = GameConnection::getServerConnection();
|
||||
if(!con)
|
||||
return;
|
||||
|
||||
ShapeBase * obj = con->getControlObject();
|
||||
if(!obj)
|
||||
return;
|
||||
|
||||
F32 val = getValue();
|
||||
|
||||
RectI rect(offset + mSubRegion.point, mSubRegion.extent);
|
||||
rect.extent.x = (S32)(rect.extent.x * val);
|
||||
|
||||
mFillColor.alpha = mOpacity;
|
||||
ColorI fill;
|
||||
getBarColor( fill );
|
||||
fill.alpha = mOpacity * 255;
|
||||
|
||||
if(mPulse && (mPulseRate != 0))
|
||||
{
|
||||
S32 time = (S32)Platform::getVirtualMilliseconds();
|
||||
F32 alpha = F32(time % mPulseRate) / F32(mPulseRate/2);
|
||||
|
||||
if(alpha > 1)
|
||||
alpha = 1.f - (alpha - 1.f);
|
||||
|
||||
fill.alpha *= alpha;
|
||||
fill.alpha *= 255;
|
||||
}
|
||||
|
||||
dglDrawRectFill(rect, fill);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void HudBarBaseCtrl::initPersistFields()
|
||||
{
|
||||
Parent::initPersistFields();
|
||||
|
||||
addField("displayMounted", TypeBool, Offset(mDisplayMounted, HudBarBaseCtrl));
|
||||
addField("pulseRate", TypeS32, Offset(mPulseRate, HudBarBaseCtrl));
|
||||
addField("pulseThreshold", TypeF32, Offset(mPulseThreshold, HudBarBaseCtrl));
|
||||
addField("verticalFill", TypeBool, Offset(mVerticalFill, HudBarBaseCtrl));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Class: HudEnergy
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class HudEnergyCtrl : public HudBarBaseCtrl
|
||||
{
|
||||
private:
|
||||
typedef HudBarBaseCtrl Parent;
|
||||
|
||||
public:
|
||||
|
||||
F32 getValue();
|
||||
|
||||
DECLARE_CONOBJECT(HudEnergyCtrl);
|
||||
};
|
||||
|
||||
IMPLEMENT_CONOBJECT(HudEnergyCtrl);
|
||||
|
||||
F32 HudEnergyCtrl::getValue()
|
||||
{
|
||||
GameConnection * con = GameConnection::getServerConnection();
|
||||
if(!con)
|
||||
return(0.f);
|
||||
|
||||
ShapeBase * obj = con->getControlObject();
|
||||
if(!obj)
|
||||
return(0.f);
|
||||
|
||||
if(mDisplayMounted)
|
||||
{
|
||||
ShapeBase * mount = obj->getObjectMount();
|
||||
while(mount && mount->isMounted())
|
||||
mount = mount->getObjectMount();
|
||||
|
||||
if(mount)
|
||||
return(mClampF(mount->getEnergyValue(), 0.f, 1.f));
|
||||
else
|
||||
return(0.f);
|
||||
}
|
||||
else
|
||||
return(mClampF(obj->getEnergyValue(), 0.f, 1.f));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Class: HudDamage
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class HudDamageCtrl : public HudBarBaseCtrl
|
||||
{
|
||||
private:
|
||||
typedef HudBarBaseCtrl Parent;
|
||||
|
||||
public:
|
||||
|
||||
F32 getValue();
|
||||
void getBarColor( ColorI &col );
|
||||
|
||||
DECLARE_CONOBJECT(HudDamageCtrl);
|
||||
};
|
||||
|
||||
IMPLEMENT_CONOBJECT(HudDamageCtrl);
|
||||
|
||||
void HudDamageCtrl::getBarColor( ColorI &col )
|
||||
{
|
||||
F32 val = getValue();
|
||||
|
||||
if( val < 0.6 && val > 0.25)
|
||||
col.set( 255, 178, 0 );
|
||||
else if( val <= 0.25 )
|
||||
col.set( 255, 0, 0 );
|
||||
else
|
||||
col.set( mFillColor.red * 255, mFillColor.green * 255, mFillColor.blue * 255);}
|
||||
|
||||
F32 HudDamageCtrl::getValue()
|
||||
{
|
||||
GameConnection * con = GameConnection::getServerConnection();
|
||||
|
||||
if(!con)
|
||||
return(0.f);
|
||||
|
||||
ShapeBase * obj = con->getControlObject();
|
||||
if( !obj )
|
||||
return (0.f);
|
||||
|
||||
mPulse = false;
|
||||
|
||||
if(dynamic_cast<Camera*>(con->getControlObject()))
|
||||
return(0.f);
|
||||
|
||||
F32 damage = 0.0f;
|
||||
|
||||
if(mDisplayMounted)
|
||||
{
|
||||
ShapeBase * mount = obj->getObjectMount();
|
||||
while(mount && mount->isMounted())
|
||||
mount = mount->getObjectMount();
|
||||
|
||||
if(mount)
|
||||
damage = mClampF(1.f - mount->getDamageValue(), 0.f, 1.f);
|
||||
else
|
||||
damage = 0.0f;
|
||||
}
|
||||
else
|
||||
damage = mClampF(1.f - obj->getDamageValue(), 0.f, 1.f);
|
||||
|
||||
|
||||
if( damage < 0.25 )
|
||||
mPulse = true;
|
||||
|
||||
return(damage);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Class: HudHeat
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class HudHeat : public HudBarBaseCtrl
|
||||
{
|
||||
private:
|
||||
typedef HudBarBaseCtrl Parent;
|
||||
|
||||
public:
|
||||
|
||||
F32 getValue();
|
||||
void onRender(Point2I, const RectI &, GuiControl *);
|
||||
|
||||
DECLARE_CONOBJECT(HudHeat);
|
||||
|
||||
static void initPersistFields();
|
||||
HudHeat();
|
||||
F32 mHeatWarning;
|
||||
};
|
||||
|
||||
IMPLEMENT_CONOBJECT(HudHeat);
|
||||
|
||||
HudHeat::HudHeat()
|
||||
{
|
||||
mHeatWarning = 0.5;
|
||||
}
|
||||
|
||||
F32 HudHeat::getValue()
|
||||
{
|
||||
GameConnection * con = GameConnection::getServerConnection();
|
||||
if(!con)
|
||||
return 0.f;
|
||||
|
||||
ShapeBase *obj = con->getControlObject();
|
||||
if(!obj)
|
||||
return 0.f;
|
||||
|
||||
if( dynamic_cast<Camera*>(obj) )
|
||||
return(0.f);
|
||||
|
||||
F32 heat = obj->getHeat();
|
||||
|
||||
if( heat > mHeatWarning )
|
||||
mPulse = true;
|
||||
else
|
||||
mPulse = false;
|
||||
|
||||
return(mClampF( heat, 0.f, 1.f));
|
||||
}
|
||||
|
||||
void HudHeat::onRender( Point2I offset, const RectI &rect, GuiControl *ctrl )
|
||||
{
|
||||
Parent::onRender( offset, rect, ctrl );
|
||||
|
||||
// need to draw a little hash here
|
||||
}
|
||||
|
||||
void HudHeat::initPersistFields()
|
||||
{
|
||||
Parent::initPersistFields();
|
||||
|
||||
addField("heatWarning", TypeF32, Offset(mHeatWarning, HudHeat));
|
||||
}
|
||||
311
hud/hudGLEx.cc
Normal file
311
hud/hudGLEx.cc
Normal file
|
|
@ -0,0 +1,311 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hud/hudGLEx.h"
|
||||
#include "math/mBezier2D.h"
|
||||
#include "math/mPoint.h"
|
||||
#include "hud/hudGLEx.h"
|
||||
#include "core/color.h"
|
||||
#include "math/mPoint.h"
|
||||
#include "math/mRect.h"
|
||||
#include "dgl/gFont.h"
|
||||
|
||||
/**
|
||||
* This function takes two colors and does a gradient line between them
|
||||
*
|
||||
* @param x1 X coordinate of the first point of the line
|
||||
* @param y1 Y coordinate of the first point of the line
|
||||
* @param x2 X coordinate of the second point of the line
|
||||
* @param y2 Y coordinate of the second point of the line
|
||||
* @param color1 Color of the first point of the line
|
||||
* @param color2 Color of the second point of the line
|
||||
*/
|
||||
void dglDrawLine( S32 x1, S32 y1, S32 x2, S32 y2, const ColorI &color1, const ColorI &color2 ) {
|
||||
glEnable( GL_BLEND );
|
||||
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
|
||||
glBegin( GL_LINES );
|
||||
glColor4ub( color1.red, color1.green, color1.blue, color1.alpha );
|
||||
glVertex2f( (F32)x1 + 0.5, (F32)y1 + 0.5 );
|
||||
|
||||
glColor4ub( color2.red, color2.green, color2.blue, color2.alpha );
|
||||
glVertex2f( (F32)x2 + 0.5, (F32)y2 + 0.5 );
|
||||
glEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function takes two colors and does a gradient line between them
|
||||
*
|
||||
* @param startPt Start point of the line
|
||||
* @param endPt End point of the line
|
||||
* @param color1 Color of the start point of the line
|
||||
* @param color2 Color of the end point of the line
|
||||
*/
|
||||
void dglDrawLine( const Point2I &startPt, const Point2I &endPt, const ColorI &color1, const ColorI &color2 ) {
|
||||
dglDrawLine( startPt.x, startPt.y, endPt.x, endPt.y, color1, color2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* This function draws a hollow rectangle and
|
||||
* does a gradient blend across it
|
||||
*
|
||||
* @param upperL Upper left corner point
|
||||
* @param lowerR Lower right corner point
|
||||
* @param color1 Upper left corner point color
|
||||
* @param color2 Lower left corner point color
|
||||
* @param color3 Upper right corner point color
|
||||
* @param color4 Lower right corner point color
|
||||
*/
|
||||
void dglDrawRect( const Point2I &upperL, const Point2I &lowerR, const ColorI &color1,
|
||||
const ColorI &color2, const ColorI &color3, const ColorI &color4 ) {
|
||||
glEnable( GL_BLEND );
|
||||
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
|
||||
glBegin( GL_LINE_LOOP );
|
||||
// Upper Left
|
||||
glColor4ub( color1.red, color1.green, color1.blue, color1.alpha );
|
||||
glVertex2f( (F32)upperL.x + 0.5, (F32)upperL.y + 0.5 );
|
||||
// Upper Right
|
||||
glColor4ub( color3.red, color3.green, color3.blue, color3.alpha );
|
||||
glVertex2f( (F32)lowerR.x + 0.5, (F32)upperL.y + 0.5 );
|
||||
// Lower Right
|
||||
glColor4ub( color4.red, color4.green, color4.blue, color4.alpha );
|
||||
glVertex2f( (F32)lowerR.x + 0.5, (F32)lowerR.y + 0.5 );
|
||||
// Lower Left
|
||||
glColor4ub( color2.red, color2.green, color2.blue, color2.alpha );
|
||||
glVertex2f( (F32)upperL.x + 0.5, (F32)lowerR.y + 0.5 );
|
||||
glEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function draws a hollow rectangle and
|
||||
* does a gradient blend across it
|
||||
*
|
||||
* @param rect Rectangle to draw
|
||||
* @param color1 Upper left corner point color
|
||||
* @param color2 Lower left corner point color
|
||||
* @param color3 Upper right corner point color
|
||||
* @param color4 Lower right corner point color
|
||||
*/
|
||||
void dglDrawRect( const RectI &rect, const ColorI &color1, const ColorI &color2,
|
||||
const ColorI &color3, const ColorI &color4 ) {
|
||||
|
||||
Point2I lowerR( rect.point.x + rect.extent.x - 1, rect.point.y + rect.extent.y - 1 );
|
||||
dglDrawRect( rect.point, lowerR, color1, color2, color3, color4 );
|
||||
}
|
||||
|
||||
/**
|
||||
* This function draws a filled rectangle and does a gradient
|
||||
* blend across it.
|
||||
*
|
||||
* @param upperL Upper left corner point
|
||||
* @param lowerR Lower right corner point
|
||||
* @param color1 Upper left corner point color
|
||||
* @param color2 Lower left corner point color
|
||||
* @param color3 Upper right corner point color
|
||||
* @param color4 Lower right corner point color
|
||||
*/
|
||||
void dglDrawRectFill( const Point2I &upperL, const Point2I &lowerR, const ColorI &color1,
|
||||
const ColorI &color2, const ColorI &color3, const ColorI &color4 ) {
|
||||
glEnable( GL_BLEND );
|
||||
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
|
||||
glBegin( GL_QUADS );
|
||||
// Upper Left
|
||||
glColor4ub( color1.red, color1.green, color1.blue, color1.alpha );
|
||||
glVertex2f( (F32)upperL.x + 0.5, (F32)upperL.y + 0.5 );
|
||||
// Upper Right
|
||||
glColor4ub( color3.red, color3.green, color3.blue, color3.alpha );
|
||||
glVertex2f( (F32)lowerR.x + 0.5, (F32)upperL.y + 0.5 );
|
||||
// Lower Right
|
||||
glColor4ub( color4.red, color4.green, color4.blue, color4.alpha );
|
||||
glVertex2f( (F32)lowerR.x + 0.5, (F32)lowerR.y + 0.5 );
|
||||
// Lower Left
|
||||
glColor4ub( color2.red, color2.green, color2.blue, color2.alpha );
|
||||
glVertex2f( (F32)upperL.x + 0.5, (F32)lowerR.y + 0.5 );
|
||||
glEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function draws a hollow rectangle and
|
||||
* does a gradient blend across it
|
||||
*
|
||||
* @param rect Rectangle to draw
|
||||
* @param color1 Upper left corner point color
|
||||
* @param color2 Lower left corner point color
|
||||
* @param color3 Upper right corner point color
|
||||
* @param color4 Lower right corner point color
|
||||
*/
|
||||
void dglDrawRectFill( const RectI &rect, const ColorI &color1,
|
||||
const ColorI &color2, const ColorI &color3, const ColorI &color4 ) {
|
||||
|
||||
Point2I lowerR( rect.point.x + rect.extent.x - 1, rect.point.y + rect.extent.y - 1 );
|
||||
dglDrawRectFill( rect.point, lowerR, color1, color2, color3, color4 );
|
||||
}
|
||||
|
||||
/**
|
||||
* This draws a Beizer curve using a line strip
|
||||
*
|
||||
* @param curve Bezier curve object to draw
|
||||
* @param color Color to draw the curve
|
||||
*/
|
||||
void dglDrawBezier( Bezier2D *curve, const ColorI &color, const Point2F &offset ) {
|
||||
|
||||
glEnable( GL_BLEND );
|
||||
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
|
||||
glColor4ub( color.red, color.green, color.blue, color.alpha );
|
||||
|
||||
glBegin( GL_LINE_STRIP );
|
||||
for( int i = 0; i < curve->getNumCurvePoints(); i++ )
|
||||
glVertex2f( curve->getCurvePoints()[i].x - offset.x, curve->getCurvePoints()[i].y - offset.y );
|
||||
glEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* This draws a Beizer curve using a line strip with a gradient
|
||||
*
|
||||
* @param curve Bezier curve object to draw
|
||||
* @param color1 First color for the curve gradient
|
||||
* @param color2 Second color for the curve gradient
|
||||
*/
|
||||
void dglDrawBezier( Bezier2D *curve, const ColorI &color1, const ColorI &color2, const Point2F &offset ) {
|
||||
ColorF colorStep;
|
||||
ColorF currColor( color1.red, color1.green, color1.blue, color1.alpha );
|
||||
|
||||
// Calculate the color steps
|
||||
F32 stepDelta = curve->getNumCurvePoints() / 100.0f;
|
||||
|
||||
colorStep.red = ( ( color2.red - color1.red ) / 85.3 ) * stepDelta;
|
||||
colorStep.green = ( ( color2.green - color1.green ) / 85.3 ) * stepDelta;
|
||||
colorStep.blue = ( ( color2.blue - color1.blue ) / 85.3 ) * stepDelta;
|
||||
|
||||
glEnable( GL_BLEND );
|
||||
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
|
||||
glBegin( GL_LINE_STRIP );
|
||||
for( int i = 0; i < curve->getNumCurvePoints(); i++ ) {
|
||||
currColor.red += colorStep.red * i;
|
||||
currColor.green += colorStep.green * i;
|
||||
currColor.blue += colorStep.blue * i;
|
||||
|
||||
glColor4ub( currColor.red, currColor.green, currColor.blue, currColor.alpha );
|
||||
glVertex2f( curve->getCurvePoints()[i].x - offset.x, curve->getCurvePoints()[i].y - offset.y );
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* This draws a Beizer curve using a quad strip
|
||||
*
|
||||
* @param curve Bezier curve object to draw
|
||||
* @param offset Delta to offset the second curve by
|
||||
* @param scale How big the second curve is in relation to the first
|
||||
* @param color Color to draw the curve
|
||||
* @param per Optional parameter, allows you to specify a percent of the graph to render
|
||||
* @param rightToLeft Optional parameter, draw the graph from right to left instead of left to right (Default)
|
||||
*/
|
||||
void dglDrawBezierBand( Bezier2D *curve, const Point2F &offset, const F32 scale, const ColorI &color, const F32 per, bool rightToLeft ) {
|
||||
Bezier2D *innerCurve = curve->getScaledCurve( scale );
|
||||
F32 percent = per;
|
||||
|
||||
if( percent > 1.0f )
|
||||
percent = 1.0f;
|
||||
else if( percent < 0.0f )
|
||||
percent = 0.0f;
|
||||
|
||||
U32 i = 0;
|
||||
U32 max = curve->getNumCurvePoints();
|
||||
|
||||
if( rightToLeft )
|
||||
i = (U32)( max * ( 1.0f - percent ) );
|
||||
else if( percent != 1.0f )
|
||||
max = (U32)( max * percent );
|
||||
|
||||
glEnable( GL_BLEND );
|
||||
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
|
||||
glColor4ub( color.red, color.green, color.blue, color.alpha );
|
||||
|
||||
glBegin( GL_QUAD_STRIP );
|
||||
for( i; i < max; i++ ) {
|
||||
glVertex2f( curve->getCurvePoints()[i].x, curve->getCurvePoints()[i].y );
|
||||
glVertex2f( innerCurve->getCurvePoints()[i].x - offset.x,
|
||||
innerCurve->getCurvePoints()[i].y - offset.y );
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* This draws a Beizer curve using a quad strip with a gradient
|
||||
*
|
||||
* @param curve Bezier curve object to draw
|
||||
* @param offset Delta to offset the second curve by
|
||||
* @param scale How big the second curve is in relation to the first
|
||||
* @param color1 First color for the curve gradient
|
||||
* @param color2 Second color for the curve gradient
|
||||
* @param per Optional parameter, allows you to specify a percent of the graph to render
|
||||
* @param rightToLeft Optional parameter, draw the graph from right to left instead of left to right (Default)
|
||||
*/
|
||||
void dglDrawBezierBand( Bezier2D *curve, const Point2F &offset, const F32 scale, const ColorI &color1, const ColorI &color2, const F32 per, bool rightToLeft ) {
|
||||
Bezier2D *innerCurve = curve->getScaledCurve( scale );
|
||||
ColorF colorStep( 0, 0, 0 );
|
||||
ColorF currColor( color1.red, color1.green, color1.blue, color1.alpha );
|
||||
F32 percent = per;
|
||||
U32 i = 0;
|
||||
U32 max = curve->getNumCurvePoints();
|
||||
|
||||
if( percent > 1.0f )
|
||||
percent = 1.0f;
|
||||
else if( percent < 0.0f )
|
||||
percent = 0.0f;
|
||||
|
||||
|
||||
// Calculate the color steps
|
||||
colorStep.red = ( (F32)color2.red - (F32)color1.red ) / (F32)curve->getNumCurvePoints();
|
||||
colorStep.green = ( (F32)color2.green - (F32)color1.green ) / (F32)curve->getNumCurvePoints();
|
||||
colorStep.blue = ( (F32)color2.blue - (F32)color1.blue ) / (F32)curve->getNumCurvePoints();
|
||||
|
||||
if( rightToLeft ) {
|
||||
i = (U32)( max * ( 1.0f - percent ) );
|
||||
currColor.set( color2.red, color2.green, color2.blue, color2.alpha );
|
||||
|
||||
colorStep.red *= -1.0f;
|
||||
colorStep.green *= -1.0f;
|
||||
colorStep.blue *= -1.0f;
|
||||
|
||||
currColor.red += i * colorStep.red;
|
||||
currColor.green += i * colorStep.green;
|
||||
currColor.blue += i * colorStep.blue;
|
||||
}
|
||||
else if( percent != 1.0f )
|
||||
max = (U32)( max * percent );
|
||||
|
||||
glEnable( GL_BLEND );
|
||||
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
|
||||
glBegin( GL_QUAD_STRIP );
|
||||
for( i; i < max; i++ ) {
|
||||
glColor4ub( currColor.red, currColor.green, currColor.blue, currColor.alpha );
|
||||
|
||||
glVertex2f( curve->getCurvePoints()[i].x, curve->getCurvePoints()[i].y );
|
||||
glVertex2f( innerCurve->getCurvePoints()[i].x - offset.x,
|
||||
innerCurve->getCurvePoints()[i].y - offset.y );
|
||||
|
||||
currColor.red += colorStep.red;
|
||||
currColor.green += colorStep.green;
|
||||
currColor.blue += colorStep.blue;
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
35
hud/hudGLEx.h
Normal file
35
hud/hudGLEx.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _HUDGLEX_H_
|
||||
#define _HUDGLEX_H_
|
||||
|
||||
#include "math/mPoint.h"
|
||||
#include "dgl/dgl.h"
|
||||
|
||||
class Bezier2D;
|
||||
|
||||
void dglDrawBezier( Bezier2D *curve, const ColorI &color, const Point2F &offset = Point2F( 0.0f, 0.0f ) );
|
||||
void dglDrawBezier( Bezier2D *curve, const ColorI &color1, const ColorI &color2, const Point2F &offset = Point2F( 0.0f, 0.0f ) );
|
||||
|
||||
void dglDrawBezierBand( Bezier2D *curve, const Point2F &offset, const F32 scale, const ColorI &color, const F32 per = 1.0f, bool rightToLeft = false );
|
||||
void dglDrawBezierBand( Bezier2D *curve, const Point2F &offset, const F32 scale, const ColorI &color1, const ColorI &color2, const F32 per = 1.0f, bool rightToLeft = false );
|
||||
|
||||
void dglDrawRectFill( const Point2I &upperL, const Point2I &lowerR, const ColorI &color1,
|
||||
const ColorI &color2, const ColorI &color3, const ColorI &color4 );
|
||||
void dglDrawRectFill( const RectI &rect, const ColorI &color1,
|
||||
const ColorI &color2, const ColorI &color3, const ColorI &color4 );
|
||||
|
||||
void dglDrawRect( const Point2I &upperL, const Point2I &lowerR, const ColorI &color1,
|
||||
const ColorI &color2, const ColorI &color3, const ColorI &color4 );
|
||||
void dglDrawRect( const RectI &rect, const ColorI &color1, const ColorI &color2,
|
||||
const ColorI &color3, const ColorI &color4 );
|
||||
|
||||
void dglDrawLine( S32 x1, S32 y1, S32 x2, S32 y2, const ColorI &color1, const ColorI &color2 );
|
||||
void dglDrawLine( const Point2I &startPt, const Point2I &endPt, const ColorI &color1, const ColorI &color2 );
|
||||
|
||||
#endif
|
||||
105
hud/hudHealthCtrl.cc
Normal file
105
hud/hudHealthCtrl.cc
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hud/hudBarDisplayCtrl.h"
|
||||
#include "game/gameConnection.h"
|
||||
#include "game/shapeBase.h"
|
||||
#include "game/camera.h"
|
||||
|
||||
/**
|
||||
* This is a health display bar graph
|
||||
*/
|
||||
class HudHealthCtrl : public HudBarDisplayCtrl {
|
||||
private:
|
||||
typedef HudBarDisplayCtrl Parent;
|
||||
|
||||
public:
|
||||
HudHealthCtrl();
|
||||
|
||||
F32 getValue();
|
||||
ColorI getBarColor();
|
||||
|
||||
DECLARE_CONOBJECT( HudHealthCtrl );
|
||||
};
|
||||
|
||||
IMPLEMENT_CONOBJECT( HudHealthCtrl );
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
HudHealthCtrl::HudHealthCtrl() {
|
||||
mHorizontalBar = false;
|
||||
mDrawFromOrigin = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method ovrrides the virtual method in hudBarBaseCtrl
|
||||
* the bar changes color depending on how much damage is taken
|
||||
*
|
||||
* @return ColorI that has the bar color stored in it
|
||||
*/
|
||||
ColorI HudHealthCtrl::getBarColor() {
|
||||
F32 val = getValue();
|
||||
|
||||
if( val < 0.6 && val > 0.25)
|
||||
return ColorI( 255, 178, 0 );
|
||||
else if( val <= 0.25 )
|
||||
return ColorI( 255, 0, 0 );
|
||||
else
|
||||
return ColorI( 0, 210, 210 );
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is overridden from hudBarBaseCtrl, it returns the
|
||||
* damage level of the player as a percentile
|
||||
*
|
||||
* @return Damage level of the player as a percentile
|
||||
*/
|
||||
F32 HudHealthCtrl::getValue() {
|
||||
|
||||
GameConnection *con = GameConnection::getServerConnection();
|
||||
|
||||
// Sanity check connection to game.
|
||||
if( !con )
|
||||
return( 0.f );
|
||||
|
||||
ShapeBase *obj = con->getControlObject();
|
||||
|
||||
if( !obj )
|
||||
return (0.f);
|
||||
|
||||
mPulse = false;
|
||||
|
||||
// If we're in a floating camera view...
|
||||
if( dynamic_cast<Camera*>( con->getControlObject() ) )
|
||||
return( 0.f );
|
||||
|
||||
// Nope, we're either on a vehicle or running around
|
||||
F32 damage = 0.0f;
|
||||
|
||||
if( mDisplayMounted ) {
|
||||
ShapeBase * mount = obj->getObjectMount();
|
||||
|
||||
while( mount && mount->isMounted() )
|
||||
mount = mount->getObjectMount();
|
||||
|
||||
if( mount )
|
||||
damage = mClampF( 1.f - mount->getDamageValue(), 0.f, 1.f );
|
||||
else
|
||||
damage = 0.0f;
|
||||
}
|
||||
else
|
||||
damage = mClampF( 1.f - obj->getDamageValue(), 0.f, 1.f );
|
||||
|
||||
|
||||
if( damage < 0.25 )
|
||||
mPulse = true;
|
||||
|
||||
return damage;
|
||||
}
|
||||
|
||||
// hudDamage.cc
|
||||
86
hud/hudHeat.cc
Normal file
86
hud/hudHeat.cc
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hudBarBaseCtrl.h"
|
||||
#include "game/gameConnection.h"
|
||||
#include "game/shapeBase.h"
|
||||
#include "game/camera.h"
|
||||
|
||||
//===========================================================================
|
||||
// CLASS: HudHeat
|
||||
//===========================================================================
|
||||
|
||||
class HudHeat : public HudBarBaseCtrl {
|
||||
private:
|
||||
typedef HudBarBaseCtrl Parent;
|
||||
|
||||
public:
|
||||
|
||||
F32 getValue();
|
||||
|
||||
DECLARE_CONOBJECT( HudHeat );
|
||||
|
||||
static void initPersistFields();
|
||||
HudHeat();
|
||||
F32 mHeatWarning;
|
||||
};
|
||||
|
||||
//===========================================================================
|
||||
// HudHeatImplementation
|
||||
//===========================================================================
|
||||
IMPLEMENT_CONOBJECT( HudHeat );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// Constructor
|
||||
//------------------------------------------------------------------
|
||||
HudHeat::HudHeat() {
|
||||
mHeatWarning = 0.5;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// getValue
|
||||
//
|
||||
// This method is overridden from hudBarBaseCtrl, it returns the
|
||||
// heat level of the player as a percentile
|
||||
//
|
||||
// Return: Heat level of the player as a percentile
|
||||
//------------------------------------------------------------------
|
||||
F32 HudHeat::getValue() {
|
||||
GameConnection *con = GameConnection::getServerConnection();
|
||||
|
||||
if(!con)
|
||||
return 0.f;
|
||||
|
||||
ShapeBase *obj = con->getControlObject();
|
||||
|
||||
if( !obj )
|
||||
return 0.f;
|
||||
|
||||
// Make sure this isn't a free camera
|
||||
if( dynamic_cast<Camera*>(obj) )
|
||||
return 0.f;
|
||||
|
||||
F32 heat = obj->getHeat();
|
||||
|
||||
if( heat > mHeatWarning )
|
||||
mPulse = true;
|
||||
else
|
||||
mPulse = false;
|
||||
|
||||
return mClampF( heat, 0.f, 1.f );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// initPersistFields
|
||||
//
|
||||
// Registers datamembers of this object with the game
|
||||
//------------------------------------------------------------------
|
||||
void HudHeat::initPersistFields() {
|
||||
Parent::initPersistFields();
|
||||
|
||||
addField( "heatWarning", TypeF32, Offset( mHeatWarning, HudHeat ) );
|
||||
}
|
||||
81
hud/hudObject.cc
Normal file
81
hud/hudObject.cc
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hud/hudObject.h"
|
||||
#include "hud/hudGLEx.h"
|
||||
#include "console/consoleTypes.h"
|
||||
|
||||
IMPLEMENT_CONOBJECT( HudObject );
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
HudObject::HudObject() {
|
||||
mFillColor.set( 0.25, 0.25, 0.25, 0.25 );
|
||||
mFrameColor.set( 0, 1, 0, 1 );
|
||||
mTextColor.set( 1, 1, 1, 1 );
|
||||
mShadowColor.set( 0, 0, 0, 1 );
|
||||
mOpacity = 1.f;
|
||||
mShowFrame = mShowFill = true;
|
||||
mUse3dText = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called to render the HUD object
|
||||
*
|
||||
* @param offset Basically the corner to begin drawing at
|
||||
* @param updateRect The rectangle that this object updates
|
||||
* @param firstResponder ?
|
||||
*/
|
||||
void HudObject::onRender( Point2I offset,
|
||||
const RectI &updateRect,
|
||||
GuiControl *firstResponder ) {
|
||||
|
||||
mFillColor.alpha = mFrameColor.alpha = mTextColor.alpha = mOpacity;
|
||||
|
||||
if( mShowFill )
|
||||
dglDrawRectFill( updateRect, mFillColor );
|
||||
if( mShowFrame )
|
||||
dglDrawRect( updateRect, mFrameColor );
|
||||
|
||||
//renderChildControls( offset, updateRect, firstResponder );
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws text on the HUD control, the reason for this is to
|
||||
* allow for some text effects, like shadows and such
|
||||
*
|
||||
* @param offset Where to begin drawing
|
||||
* @param buf The buffer of text to display
|
||||
*/
|
||||
void HudObject::drawText( Point2I offset, char *buf ) {
|
||||
if( mUse3dText ) {
|
||||
dglSetBitmapModulation( mShadowColor );
|
||||
dglDrawText( mProfile->mFont, Point2I( offset.x - 2, offset.y + 2 ), buf );
|
||||
}
|
||||
|
||||
dglSetBitmapModulation( mTextColor );
|
||||
dglDrawText( mProfile->mFont, offset, buf );
|
||||
dglClearBitmapModulation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers console-modifyable datamembers
|
||||
*/
|
||||
void HudObject::initPersistFields() {
|
||||
Parent::initPersistFields();
|
||||
addField( "fillColor", TypeColorF, Offset( mFillColor, HudObject ) );
|
||||
addField( "frameColor", TypeColorF, Offset( mFrameColor, HudObject ) );
|
||||
addField( "textColor", TypeColorF, Offset( mTextColor, HudObject ) );
|
||||
addField( "shadowColor", TypeColorF, Offset( mShadowColor, HudObject ) );
|
||||
addField( "opacity", TypeF32, Offset( mOpacity, HudObject ) );
|
||||
addField( "showFill", TypeBool, Offset( mShowFill, HudObject ) );
|
||||
addField( "showFrame", TypeBool, Offset( mShowFrame, HudObject ) );
|
||||
addField( "use3dText", TypeBool, Offset( mUse3dText, HudObject ) );
|
||||
}
|
||||
|
||||
// hudObject.cc
|
||||
51
hud/hudObject.h
Normal file
51
hud/hudObject.h
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _HUDOBJECT_H_
|
||||
#define _HUDOBJECT_H_
|
||||
|
||||
#include "gui/guiControl.h"
|
||||
|
||||
/**
|
||||
* This class is the top level as far as far as HUD controls go.
|
||||
* This will allow for inherited behavior such as hud-movers etc.
|
||||
*/
|
||||
class HudObject : public GuiControl {
|
||||
private:
|
||||
typedef GuiControl Parent;
|
||||
|
||||
protected:
|
||||
void drawText( Point2I offset, char *buf );
|
||||
|
||||
public:
|
||||
|
||||
HudObject();
|
||||
|
||||
// GuiControl
|
||||
virtual void onRender( Point2I offset,
|
||||
const RectI &updateRect,
|
||||
GuiControl *firstResponder );
|
||||
|
||||
// field data
|
||||
ColorF mFillColor;
|
||||
ColorF mFrameColor;
|
||||
ColorF mTextColor;
|
||||
ColorF mShadowColor;
|
||||
F32 mOpacity;
|
||||
bool mShowFrame;
|
||||
bool mShowFill;
|
||||
bool mUse3dText;
|
||||
|
||||
|
||||
static void initPersistFields();
|
||||
|
||||
DECLARE_CONOBJECT( HudObject );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// hudObject.h
|
||||
83
hud/hudZoom.cc
Normal file
83
hud/hudZoom.cc
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hud/hudBitmapCtrl.h"
|
||||
#include "dgl/dgl.h"
|
||||
|
||||
class HudZoom : public HudBitmapCtrl
|
||||
{
|
||||
typedef HudBitmapCtrl Parent;
|
||||
public:
|
||||
void getPoints(Point2I *point, Point2I offset);
|
||||
HudZoom();
|
||||
~HudZoom();
|
||||
DECLARE_CONOBJECT(HudZoom);
|
||||
void onRender(Point2I offset, const RectI &updateRect, GuiControl *firstResponder);
|
||||
void findLastColor(char *line, Vector<U32> lineStarts, ColorI *useColor);
|
||||
};
|
||||
|
||||
IMPLEMENT_CONOBJECT(HudZoom);
|
||||
|
||||
HudZoom::HudZoom()
|
||||
{
|
||||
}
|
||||
|
||||
HudZoom::~HudZoom()
|
||||
{
|
||||
}
|
||||
|
||||
void HudZoom::onRender(Point2I offset, const RectI &updateRect, GuiControl *firstResponder)
|
||||
{
|
||||
if(mBitmapHandle)
|
||||
Parent::onRender(offset, updateRect, firstResponder);
|
||||
else
|
||||
{
|
||||
S32 x;
|
||||
Point2I point[12];
|
||||
getPoints(point, offset);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
glColor4ub(mProfile->mBorderColor.red, mProfile->mBorderColor.green, mProfile->mBorderColor.blue, mProfile->mBorderColor.alpha);
|
||||
|
||||
for(x=0;x<4; ++x)
|
||||
{
|
||||
glBegin(GL_LINE_STRIP);
|
||||
glVertex2i(point[x*3 ].x, point[x*3 ].y);
|
||||
glVertex2i(point[x*3+1].x, point[x*3+1].y);
|
||||
glVertex2i(point[x*3+2].x, point[x*3+2].y);
|
||||
glEnd();
|
||||
}
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
}
|
||||
|
||||
void HudZoom::getPoints(Point2I *point, Point2I offset)
|
||||
{
|
||||
Point2I cPoint[4];
|
||||
cPoint[0] = Point2I(offset.x+1, offset.y+1);
|
||||
cPoint[1] = Point2I(offset.x-1 + mBounds.extent.x, offset.y+1);
|
||||
cPoint[2] = Point2I(offset.x-1 + mBounds.extent.x, offset.y-1 + mBounds.extent.y);
|
||||
cPoint[3] = Point2I(offset.x+1, offset.y-1 + mBounds.extent.y);
|
||||
|
||||
point[0] = Point2I(cPoint[0].x, cPoint[0].y + mBounds.extent.y/4);
|
||||
point[1] = Point2I(cPoint[0].x, cPoint[0].y);
|
||||
point[2] = Point2I(cPoint[0].x + mBounds.extent.x/4, cPoint[0].y);
|
||||
|
||||
point[3] = Point2I(cPoint[1].x - mBounds.extent.x/4, cPoint[1].y);
|
||||
point[4] = Point2I(cPoint[1].x, cPoint[1].y);
|
||||
point[5] = Point2I(cPoint[1].x, cPoint[1].y + mBounds.extent.y/4);
|
||||
|
||||
point[6] = Point2I(cPoint[2].x, cPoint[2].y - mBounds.extent.y/4);
|
||||
point[7] = Point2I(cPoint[2].x, cPoint[2].y);
|
||||
point[8] = Point2I(cPoint[2].x - mBounds.extent.x/4, cPoint[2].y);
|
||||
|
||||
point[9] = Point2I(cPoint[3].x +mBounds.extent.x/4, cPoint[3].y);
|
||||
point[10] = Point2I(cPoint[3].x, cPoint[3].y);
|
||||
point[11] = Point2I(cPoint[3].x, cPoint[3].y - mBounds.extent.y/4);
|
||||
}
|
||||
225
hud/mBezier2D.cc
Normal file
225
hud/mBezier2D.cc
Normal file
|
|
@ -0,0 +1,225 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "math/mBezier2D.h"
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param inCtrlPts Array of control points to define the curve
|
||||
* @param inPtsSize Size of the array of control points
|
||||
* @param numCurvePts Number of points to be calculated for the curve
|
||||
*/
|
||||
Bezier2D::Bezier2D( const Point2F *inCtrlPts, const U32 inPtsSize, const U32 numCurvePts ) {
|
||||
mControlPoints = new Point2F[inPtsSize];
|
||||
mCurvePoints = NULL;
|
||||
mLastScaledCurve = NULL;
|
||||
mLastScaleValue = 1.0f;
|
||||
|
||||
mNumCurvePoints = numCurvePts;
|
||||
mNumCtrlPoints = inPtsSize;
|
||||
|
||||
if( mNumCurvePoints < MBEZIER2D_MIN_CURVE_POINTS )
|
||||
mNumCurvePoints = MBEZIER2D_MIN_CURVE_POINTS;
|
||||
else if( mNumCurvePoints > MBEZIER2D_MAX_CURVE_POINTS )
|
||||
mNumCurvePoints = MBEZIER2D_MAX_CURVE_POINTS;
|
||||
|
||||
for( int i = 0; i < inPtsSize; i++ )
|
||||
mControlPoints[i] = inCtrlPts[i];
|
||||
|
||||
calcCurve();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
Bezier2D::~Bezier2D() {
|
||||
delete [] mControlPoints;
|
||||
delete [] mCurvePoints;
|
||||
|
||||
if( mLastScaledCurve != NULL )
|
||||
delete mLastScaledCurve;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the curve based on the control points.
|
||||
* Uses de Casteljau's algorithm. References:
|
||||
*
|
||||
* -http://www.css.tayloru.edu/~btoll/s99/424/res/mtu/Notes/spline/de-casteljau.htm
|
||||
* -http://astronomy.swin.edu.au/pbourke/curves/bezier/
|
||||
*/
|
||||
void Bezier2D::calcCurve() {
|
||||
Point2F *tempPointArray = new Point2F[mNumCtrlPoints];
|
||||
|
||||
F32 precision = ( 1.0f / mNumCurvePoints );
|
||||
|
||||
if( mCurvePoints != NULL )
|
||||
delete [] mCurvePoints;
|
||||
|
||||
mCurvePoints = new Point2F[mNumCurvePoints];
|
||||
S32 idx = 0;
|
||||
|
||||
F32 u = 0.0f;
|
||||
for( S32 i = 0; i < mNumCurvePoints; i++ ) {
|
||||
for( S32 i = 0; i < mNumCtrlPoints; i++ )
|
||||
tempPointArray[i] = mControlPoints[i]; // Making copies...grrr
|
||||
|
||||
u += precision;
|
||||
for( S32 j = 1; j < mNumCtrlPoints; j++ )
|
||||
for( S32 k = 0; k < mNumCtrlPoints - j; k++ )
|
||||
tempPointArray[k] = ( 1 - u ) * tempPointArray[k] + u * tempPointArray[k + 1];
|
||||
|
||||
mCurvePoints[idx].set( tempPointArray[0].x, tempPointArray[0].y );
|
||||
idx++;
|
||||
}
|
||||
|
||||
mRescale = true;
|
||||
|
||||
mCurveLength = 0.0f;
|
||||
for( S32 i = 1; i < mNumCurvePoints; i++ ) {
|
||||
Point2F &pt1 = mCurvePoints[i - 1];
|
||||
Point2F &pt2 = mCurvePoints[i];
|
||||
mCurveLength += mSqrt( mPow( pt2.x - pt1.x, 2.0f) + mPow( pt2.y - pt1.y, 2.0f ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives the curve a new set of control points and recalculates
|
||||
*
|
||||
* @param inCtrlPts Array of control points to define the curve
|
||||
* @param inPtsSize Size of the array of control points
|
||||
*/
|
||||
void Bezier2D::setControlPoints( const Point2F *inCtrlPts, const U32 inPtsSize ) {
|
||||
delete [] mControlPoints;
|
||||
|
||||
mControlPoints = new Point2F[inPtsSize];
|
||||
|
||||
for( int i = 0; i < inPtsSize; i++ )
|
||||
mControlPoints[i] = inCtrlPts[i];
|
||||
|
||||
mNumCtrlPoints = inPtsSize;
|
||||
|
||||
calcCurve();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new precision value, and recalculates the curve
|
||||
*
|
||||
* @param precision How precice the curve caluclations will be. 0.0f < precision < 1.0f
|
||||
* Smaller value = more precise
|
||||
*/
|
||||
void Bezier2D::setNumCalcPoints( const U32 numCurvePts ) {
|
||||
mNumCurvePoints = numCurvePts;
|
||||
|
||||
calcCurve();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of points this object is calculating
|
||||
* for the Bezier it represents
|
||||
*
|
||||
* @return Number of curve points calculating
|
||||
*/
|
||||
U32 Bezier2D::getNumCurvePoints() const {
|
||||
return mNumCurvePoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of control points in this Bezier curve
|
||||
*
|
||||
* @return Number of control points
|
||||
*/
|
||||
U32 Bezier2D::getNumCtrlPoints() const {
|
||||
return mNumCtrlPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the control points for this Bezier in an array
|
||||
*
|
||||
* @return Control points for this Bezier
|
||||
*/
|
||||
Point2F *Bezier2D::getControlPoints() const {
|
||||
return mControlPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the calculated curve points with the precision set earlier
|
||||
*
|
||||
* @return The points needed to render this curve
|
||||
*/
|
||||
Point2F *Bezier2D::getCurvePoints() const {
|
||||
return mCurvePoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the length of the calculated curve
|
||||
*
|
||||
* @return Length of the calculated curve
|
||||
*/
|
||||
F32 Bezier2D::getCurveLength() const {
|
||||
return mCurveLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scales the curve (by scaling the control points and recalculating the curve)
|
||||
* Saves the last values so repeated requests for the same scale value don't require recalculation
|
||||
*
|
||||
* @param scaleValue Value to scale the curve by, scaleValue > 0
|
||||
* @return A Bezier2D object with the new curve contained in it
|
||||
*/
|
||||
Bezier2D *Bezier2D::getScaledCurve( const F32 scaleValue ) {
|
||||
if( !mRescale && mLastScaleValue == scaleValue )
|
||||
return mLastScaledCurve;
|
||||
|
||||
Point2F *tempPoints = new Point2F[mNumCtrlPoints];
|
||||
//F32 areaPolygon = 0.0f;
|
||||
Point2F centroid( 0.0f, 0.0f );
|
||||
|
||||
for( int i = 0; i < mNumCtrlPoints; i++ ) {
|
||||
tempPoints[i] = mControlPoints[i];
|
||||
|
||||
Point2F &currPt = mControlPoints[i];
|
||||
//Point2F nextPt;
|
||||
//if( i + 1 == mNumCtrlPoints )
|
||||
// nextPt = mControlPoints[0];
|
||||
//else
|
||||
// nextPt = mControlPoints[i + 1];
|
||||
|
||||
//areaPolygon += currPt.x * nextPt.y - nextPt.x * currPt.y;
|
||||
|
||||
centroid.x += currPt.x;
|
||||
centroid.y += currPt.y;
|
||||
//centroid.x += ( currPt.x + nextPt.x ) * ( currPt.x * nextPt.y - nextPt.x * currPt.y );
|
||||
//centroid.y += ( currPt.y + nextPt.y ) * ( currPt.x * nextPt.y - nextPt.x * currPt.y );
|
||||
}
|
||||
|
||||
//areaPolygon *= .5f;
|
||||
//centroid.x *= ( 1 / 6 * areaPolygon );
|
||||
//centroid.y *= ( 1 / 6 * areaPolygon );
|
||||
centroid.x /= mNumCtrlPoints;
|
||||
centroid.y /= mNumCtrlPoints;
|
||||
|
||||
for( int i = 0; i < mNumCtrlPoints; i++ ) {
|
||||
tempPoints[i].x -= centroid.x;
|
||||
tempPoints[i].y -= centroid.y;
|
||||
|
||||
tempPoints[i].x *= scaleValue;
|
||||
tempPoints[i].y *= scaleValue;
|
||||
|
||||
tempPoints[i].x += centroid.x;
|
||||
tempPoints[i].y += centroid.y;
|
||||
}
|
||||
if( mLastScaledCurve != NULL )
|
||||
delete mLastScaledCurve;
|
||||
|
||||
mLastScaledCurve = new Bezier2D( tempPoints, mNumCtrlPoints, mNumCurvePoints );
|
||||
mRescale = false;
|
||||
|
||||
delete [] tempPoints;
|
||||
|
||||
return mLastScaledCurve;
|
||||
}
|
||||
50
hud/mBezier2D.h
Normal file
50
hud/mBezier2D.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _BEZIER2D_H_
|
||||
#define _BEZIER2D_H_
|
||||
|
||||
// For some reason, the engine will bomb out if you try to make a curve with 50+ calculated points
|
||||
#define MBEZIER2D_MIN_CURVE_POINTS 2
|
||||
#define MBEZIER2D_MAX_CURVE_POINTS 49
|
||||
|
||||
#include "math/mPoint.h"
|
||||
|
||||
class Bezier2D {
|
||||
|
||||
private:
|
||||
Point2F *mControlPoints;
|
||||
Point2F *mCurvePoints;
|
||||
|
||||
U32 mNumCtrlPoints;
|
||||
U32 mNumCurvePoints;
|
||||
F32 mCurveLength;
|
||||
|
||||
bool mRescale;
|
||||
Bezier2D *mLastScaledCurve;
|
||||
F32 mLastScaleValue;
|
||||
|
||||
void calcCurve();
|
||||
|
||||
public:
|
||||
Bezier2D( const Point2F *inCtrlPts, const U32 inPtsSize, const U32 numCurvePts );
|
||||
~Bezier2D();
|
||||
|
||||
void setControlPoints( const Point2F *inCtrlPts, const U32 inPtsSize );
|
||||
void setNumCalcPoints( const U32 numCurvePts );
|
||||
|
||||
U32 getNumCurvePoints() const;
|
||||
U32 getNumCtrlPoints() const;
|
||||
Point2F *getControlPoints() const;
|
||||
Point2F *getCurvePoints() const;
|
||||
F32 getCurveLength() const;
|
||||
|
||||
Bezier2D *getScaledCurve( const F32 scaleValue );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// mBezier2D.h
|
||||
Loading…
Add table
Add a link
Reference in a new issue