[SOLVED]I want to create the effect of radar scanning

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

classfly
Just popping in
Just popping in
Posts: 17
Joined: Mon Feb 27, 2012 08:36

[SOLVED]I want to create the effect of radar scanning

Postby classfly » 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:

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.
Last edited by classfly on Tue Mar 27, 2012 12:12, edited 2 times in total.

classfly
Just popping in
Just popping in
Posts: 17
Joined: Mon Feb 27, 2012 08:36

Re: I want to create the effect of radar scanning,but i fail

Postby classfly » Mon Feb 27, 2012 09:57

My OGRE version is 1.7.3 and 0.7.5 for CEGUI

zaexage
Just popping in
Just popping in
Posts: 15
Joined: Wed Mar 02, 2011 02:43

Re: I want to create the effect of radar scanning,but i fail

Postby zaexage » Tue Feb 28, 2012 03:26

well, the case might not be the same, but I think this might be of some use or reference.

we once created the a round skill cool-down effect like in the WOW, the main work here is also use the RenderEffect;
What's different here is we used a directx effect script, i think it might be easier to code & adjust in .fx than in .cpp;

hope it may help. :wink:

classfly
Just popping in
Just popping in
Posts: 17
Joined: Mon Feb 27, 2012 08:36

Re: I want to create the effect of radar scanning,but i fail

Postby classfly » Tue Feb 28, 2012 05:15

zaexage wrote:well, the case might not be the same, but I think this might be of some use or reference.

we once created the a round skill cool-down effect like in the WOW, the main work here is also use the RenderEffect;
What's different here is we used a directx effect script, i think it might be easier to code & adjust in .fx than in .cpp;

hope it may help. :wink:

Thanks for your reply.I know we can create that effect by using .fx,but i am not very familiar with using it.I try to find where the problem may set,and finally i find it!The fuctions of my class can be called correctly when I use it in the CEGUI Samples.And what's difference between my own project and the CEGUI sample project is that the codes did't go into the CEGUI::Window::update() function as i wished.So,the function: update() did't go in to the render progress at all.I have already over-write the function which is inheritated from class RenderEffect( update() in my SectorEffect.But the truth is that update() was not called .I really don't know why?

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: I want to create the effect of radar scanning,but i fail

Postby CrazyEddie » Tue Feb 28, 2012 07:18

classfly wrote:I have already over-write the function which is inheritated from class RenderEffect( update() in my SectorEffect.But the truth is that update() was not called .I really don't know why?

Can you confirm that you are injecting time pulses via CEGUI::System::injectTimePulse - as that's one reason why the update might not be called.

CE.

edit by Kulik - fixed quote markup

classfly
Just popping in
Just popping in
Posts: 17
Joined: Mon Feb 27, 2012 08:36

Re: I want to create the effect of radar scanning,but i fail

Postby classfly » Tue Feb 28, 2012 07:39

CrazyEddie wrote:[quote="classfly"I have already over-write the function which is inheritated from class RenderEffect( update() in my SectorEffect.But the truth is that update() was not called .I really don't know why?

Can you confirm that you are injecting time pulses via CEGUI::System::injectTimePulse - as that's one reason why the update might not be called.

CE.[/quote]
Sorry for my carelessness.Thar's the point.I forget to inject time pulses in frameRenderQueued().Thank you for your answers.The problem was solved!


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 9 guests