[SOLVED]I want to create the effect of radar scanning
Posted: Mon Feb 27, 2012 09:54
hi,recently i have got frustrated by the problem of how to create the effect of radar scanning on the texture.I have got SectorEffect.h as the following:
Here is the.cpp file
And I try to create the effect of radar scanning
,finally I got frustrated by the scene displayed on the screen which is not what i want .Sorry for my poor English.
Code: Select all
#ifndef _CSMALL_SECTOR_EFFECT_H
#define _CSMALL_SECTOR_EFFECT_H
#include "CEGUIRenderingWindow.h"
#include "CEGUIRenderEffect.h"
#include "CEGUIGeometryBuffer.h"
#include "CEGUITextureTarget.h"
#include "CEGUIVertex.h"
#include <math.h>
//effect of the sector
namespace CEGUI
{
class SectorEffect : public CEGUI::RenderEffect
{
public:
SectorEffect();
SectorEffect(float flower, bool start = true, float startAngle = 3.1415926f * 0.5f, bool anitClock = true);
// implement required functions from RenderEffect interface.
int getPassCount() const;
void performPreRenderFunctions(const int pass);
void performPostRenderFunctions();
bool realiseGeometry(CEGUI::RenderingWindow& window, CEGUI::GeometryBuffer& geometry);
bool update(const float elapsed, CEGUI::RenderingWindow& window);
//set the area of the sector
void setSectorBuffer(CEGUI::RenderingWindow& window, CEGUI::GeometryBuffer& geometry);
//set the area of the circle
void setRoundBuffer(CEGUI::RenderingWindow& window, CEGUI::GeometryBuffer& geometry);
//the rectangle
void setFangBuffer(CEGUI::RenderingWindow& window, CEGUI::GeometryBuffer& geometry);
//set the start angle
void setStartAngle(float angle);
void setStart(bool start);
bool getStart();
void setStepSize(int step);
int getStep(void);
void setProgress(float progress);
float getProgress(void);
void setAnitClockWise(bool anitClock);
void setWindowFlowers(float flower);
protected:
CEGUI::Vertex setRound(int radius, int argleNum, int offsetX, int offsetY, CEGUI::colour c);
static const int buffsize = 512 * 3;
static const float PI;
CEGUI::Vertex vb[buffsize];
int currentStep;
int addStep;
int anticlockwise;
bool bufferSet;
bool isStart;
float startAngle;
float tempAngle;
float windowFlower;
};
}
#endif
Here is the.cpp file
Code: Select all
#include"SectorEffect.h"
namespace CEGUI
{
const float SectorEffect::PI(3.1415926f);
//----------------------------------------------------------------------------//
SectorEffect::SectorEffect()
{
currentStep = 0;
bufferSet = false;
startAngle = PI * 0.5f; // PI * 0.5f
isStart = true;
addStep = 1;
anticlockwise = -1;
windowFlower = 1.0f;
}
SectorEffect::SectorEffect(float flower, bool start, float startAngle, bool anitClock)
: startAngle(startAngle)
, windowFlower(flower)
, isStart(start)
{
if (isStart)
{
currentStep = 0;
}
else
{
currentStep = buffsize - 1;
}
bufferSet = false;
addStep = 1;
setStartAngle(startAngle);
setAnitClockWise(anitClock);
}
//----------------------------------------------------------------------------//
int SectorEffect::getPassCount() const
{
return 1;
}
//----------------------------------------------------------------------------//
void SectorEffect::performPreRenderFunctions(const int /*pass*/)
{
}
//----------------------------------------------------------------------------//
void SectorEffect::performPostRenderFunctions()
{
}
//----------------------------------------------------------------------------//
bool SectorEffect::realiseGeometry(CEGUI::RenderingWindow& window, CEGUI::GeometryBuffer& geometry)
{
//scan the setRoundBuffer, only initialise once
if(!bufferSet)
setRoundBuffer(window, geometry);
//in order to display dynamically
if (isStart)
{
currentStep += addStep;
if (currentStep > buffsize - 1)
{
currentStep = 1;
}
geometry.setActiveTexture(&window.getTextureTarget().getTexture());
}
geometry.appendGeometry(vb, currentStep);
// false, because we do not want the default geometry added!
return false;
}
//----------------------------------------------------------------------------//
bool SectorEffect::update(const float elapsed, CEGUI::RenderingWindow& window)
{
if (isStart)
{
//fresh automatically
window.invalidateGeometry();
window.realiseGeometry();
}
return true;
}
//the sector area
void SectorEffect::setSectorBuffer(CEGUI::RenderingWindow& window, CEGUI::GeometryBuffer& geometry)
{
using namespace CEGUI;
CEGUI::Texture& tex = window.getTextureTarget().getTexture();
CEGUI::colour c(1, 1, 1, 1);
int argleNum = buffsize/6;
float angle = 2* PI /argleNum;
float offsetX = window.getSize().d_width/2;
float offsetY = window.getSize().d_height/2;
float radius1 = std::min(window.getSize().d_width/2,window.getSize().d_height/2);
//radius1 = 59; // radius1 = 56;
float radius2 = radius1 - 5;
float scaleRaius = radius1 / radius2;
int index = 0;
for (float j=0;j<argleNum;)
{
Vector3 p[4];
Vector2 t[4];
float rads = angle * j;
float sine = sin(rads);
float cosine = cos(rads);
p[0] = Vector3(offsetX + radius1 * cosine, offsetY - radius1 * sine, 0.0f);
t[0] = Vector2(0.5f * cosine + 0.5f, -0.5f * sine + 0.5f);
p[2] = Vector3(offsetX + radius2 * cosine, offsetY - radius2 * sine, 0.0f);
t[2] = Vector2((0.5f * cosine + 0.5f) / scaleRaius, (-0.5f * sine + 0.5f) / scaleRaius);
rads = angle * (j + 1);
sine = sin(rads);
cosine = cos(rads);
p[1] = Vector3(offsetX + radius1 * cosine, offsetY - radius1 * sine, 0.0f);
t[1] = Vector2(0.5f * cosine + 0.5f, -0.5f * sine + 0.5f);
p[3] = Vector3(offsetX + radius2 * cosine, offsetY - radius2 * sine, 0.0f);
t[3] = Vector2((0.5f * cosine + 0.5f) / scaleRaius, (-0.5f * sine + 0.5f) /scaleRaius);
// triangle 1
vb[index + 0].position = p[0];
vb[index + 1].position = p[1];
vb[index + 2].position = p[2];
vb[index + 0].tex_coords = t[0];
vb[index + 1].tex_coords = t[1];
vb[index + 2].tex_coords = t[2];
vb[index + 0].colour_val = c;
vb[index + 1].colour_val = c;
vb[index + 2].colour_val = c;
// triangle 2
vb[index + 3].position = p[2];
vb[index + 4].position = p[1];
vb[index + 5].position = p[3];
vb[index + 3].tex_coords = t[2];
vb[index + 4].tex_coords = t[1];
vb[index + 5].tex_coords = t[3];
vb[index + 3].colour_val = c;
vb[index + 4].colour_val = c;
vb[index + 5].colour_val = c;
index += 6;
j += 1.0f;
}
geometry.setActiveTexture(&tex);
//geometry.appendGeometry(vb,argleNum * 6);
bufferSet = true;
}
//the circle area
void SectorEffect::setRoundBuffer(CEGUI::RenderingWindow& window, CEGUI::GeometryBuffer& geometry)
{
using namespace CEGUI;
Texture& tex = window.getTextureTarget().getTexture();
static const CEGUI::colour c(1, 1, 1, 1);
int argleNum = buffsize/3;
float angle = 2 * PI /argleNum;
float offsetX = window.getSize().d_width/2;
float offsetY = window.getSize().d_height/2;
float radius = std::min(window.getSize().d_width/2,window.getSize().d_height/2);
for (int j=0;j<argleNum;j++)
{
int i = j*3;
float rads = angle * j + startAngle;
float sine = sin(rads);
float cosine = cos(rads);
vb[i].position = Vector3( offsetX - radius * cosine, offsetY - radius * sine * anticlockwise , 0.0f);
vb[i].tex_coords = Vector2( 0.5f * (1 - cosine), 0.5f * (1 - sine * anticlockwise));
vb[i].colour_val = c;
float rads1 = angle * (j + windowFlower) + startAngle;
float sine1 = sin(rads1);
float cosine1 = cos(rads1);
vb[i+1].position = Vector3( offsetX - radius * cosine1, offsetY - radius * sine1 * anticlockwise, 0.0f);
vb[i+1].tex_coords = Vector2(0.5f * (1 - cosine1), 0.5f * (1 - sine1 * anticlockwise));
vb[i+1].colour_val = c;
vb[i+2].position = Vector3(offsetX, offsetY, 0.0f);
vb[i+2].tex_coords = Vector2(0.5f, 0.5f);
vb[i+2].colour_val = c;
currentStep += 3;
}
if(isStart)
{
geometry.setActiveTexture(&tex);
//geometry.appendGeometry(vb,argleNum * 3);
}
bufferSet = true;
}
//the start angle
void SectorEffect::setStartAngle(float angle)
{
tempAngle = angle;
if (anticlockwise == 1)
{
startAngle = angle;
}
if (anticlockwise == -1)
{
startAngle = angle - PI;
}
}
void SectorEffect::setStart(bool start)
{
isStart = start;
}
bool SectorEffect::getStart()
{
return isStart;
}
void SectorEffect::setStepSize(int step)
{
if (step > buffsize - 1)
return;
addStep = step;
}
int SectorEffect::getStep(void)
{
return addStep;
}
void SectorEffect::setProgress(float progress)
{
if (progress > 1.0f || progress < 0.0f)
return;
currentStep = static_cast<int>(progress * (buffsize - 1));
}
float SectorEffect::getProgress(void)
{
return (currentStep / (buffsize - 1.0f));
}
void SectorEffect::setAnitClockWise(bool anitClock)
{
((anitClock == true) ? (anticlockwise = -1) : (anticlockwise = 1));
//initialise the start angle again
setStartAngle(tempAngle);
}
void SectorEffect::setWindowFlowers(float flower)
{
windowFlower = flower;
}
}
And I try to create the effect of radar scanning
Code: Select all
skillScan = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticImage", "roundProgress2");
skillScan->setProperty(("UnifiedAreaRect"),("{{0.3, 0.0},{0.1,0.0},{0.3,128},{0.1,128}}"));
skillScan->setProperty("FrameEnabled", "false");
skillScan->setProperty("BackgroundEnabled", "false");
CEGUI::ImagesetManager::getSingleton().createFromImageFile("roundProgress2", "A_star_1.tga");
skillScan->setProperty("Image", "set:roundProgress2 image:full_image");
skillScan->setProperty("AutoRenderingSurface","true");
skillScanEffect.setStartAngle(3.1415926f * 0.5f);//SectorEffect skillScanEffect;
skillScanEffect.setAnitClockWise(false);
if (skillScan && skillScan->getRenderingSurface())
static_cast<CEGUI::RenderingWindow*>(skillScan->getRenderingSurface())->setRenderEffect(&skillScanEffect);
background->addChildWindow(skillScan);//Window* background = winMgr.createWindow("DefaultWindow", "Root");
,finally I got frustrated by the scene displayed on the screen which is not what i want .Sorry for my poor English.