OpenGL Spectrum, Only One Point Visible

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

31 Replies - 1801 Views - Last Post: 21 March 2013 - 10:48 PM Rate Topic: -----

#31 Hezekiah  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 208
  • View blog
  • Posts: 552
  • Joined: 12-July 09

Re: OpenGL Spectrum, Only One Point Visible

Posted 21 March 2013 - 10:11 PM

gluPerspective will not be the best solution here, as its main use is to make objects further from the camera look smaller. You simply want to scale everything, so use glScalef.

If the width is more than the height, you want to scale the x coordinate so that it is between -(height/width) and (height/width) instead of -1 and 1.
glScalef(height / width, 1, 1)


If the height is more than the width, you want to scale the y coordinate so that it is between -(width/height) and (width/height) instead of -1 and 1.
glScalef(1, width / height, 1)

Was This Post Helpful? 1
  • +
  • -

#32 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: OpenGL Spectrum, Only One Point Visible

Posted 21 March 2013 - 10:48 PM

Thanks. Will look into it later :)/>/>

Sorry for all the questions, but this just have to be the last one.
This is the last renderer than i'm going to port from canvas.
The original looks like this
Attached Image
It's like a circular bar-graph. The bars move out.

This is the behavior i get
Attached Image

As you can see, it's very inconsistaint. Some bars move in and some out. Some actually move both ways.

This is the code i used for the canvas:
 @Override
  public void onRender(Canvas canvas, FFTData data, Rect rect)
  {
    if(mCycleColor)
    {
      cycleColor();
    }

    for (int i = 0; i < data.bytes.length / mDivisions; i++) {
      // Calculate dbValue
      byte rfk = data.bytes[mDivisions * i];
      byte ifk = data.bytes[mDivisions * i + 1];
      float magnitude = (rfk * rfk + ifk * ifk);
      float dbValue = 75 * (float)Math.log10(magnitude);

      float[] cartPoint = {
          (float)(i * mDivisions) / (data.bytes.length - 1),
          rect.height() / 2 - dbValue / 4
      };

      float[] polarPoint = toPolar(cartPoint, rect);
      mFFTPoints[i * 4] = polarPoint[0];
      mFFTPoints[i * 4 + 1] = polarPoint[1];

      float[] cartPoint2 = {
          (float)(i * mDivisions) / (data.bytes.length - 1),
          rect.height() / 2 + dbValue
      };

      float[] polarPoint2 = toPolar(cartPoint2, rect);
      mFFTPoints[i * 4 + 2] = polarPoint2[0];
      mFFTPoints[i * 4 + 3] = polarPoint2[1];
    }
    mBackPaint = new Paint();
    mBackPaint.setAntiAlias(true);
    mBackPaint.setColor(Color.parseColor("#4A1D1D1D"));
      canvas.drawPaint(mBackPaint); 
    canvas.drawLines(mFFTPoints, mPaint);

    // Controls the pulsing rate
    modulation += 0.04;
    angleModulation += 0.04;
  }

  float modulation = 0;
  float modulationStrength = 0.4f; // 0-1
  float angleModulation = 0;
  float aggresive = 0.4f;
  private float[] toPolar(float[] cartesian, Rect rect)
  {
    double cX = rect.width()/2;
    double cY = rect.height()/2;
    double angle = (cartesian[0]) * 2 * Math.PI;
    double radius = ((rect.height()/2) * (1 - aggresive) + aggresive * cartesian[1]/2) * ((1 - modulationStrength) + modulationStrength * (1 + Math.sin(modulation)) / 2);
    float[] out = {
        (float)(cX + radius * Math.sin(angle + angleModulation)),
        (float)(cY + radius * Math.cos(angle + angleModulation))
    };
    return out;
  }



and this is the code i use for the OpenGL:
@Override
public void onDrawFrame(GL10 gl) {
	gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
	gl.glLoadIdentity();
	//gl.glTranslatef(0.0f, 0.0f, -3.0f);

    if (mBytes != null) {
    	if (mFFTPoints == null || mFFTPoints.length < (mFFTBytes.length - 1) * 6) {
    		mFFTPoints = new float[(mFFTBytes.length - 1) * 6];
	      }
    	
	 if (mFFTPoints != null) {
		// Calculate points for line
		 
		 
		 
		 for (int i = 0; i < mFFTBytes.length / 32 ; i++) {
		      // Calculate dbValue
		      byte rfk = mFFTBytes[32* i];
		      byte ifk = mFFTBytes[32 * i  + 1];
		      float magnitude = (rfk * rfk + ifk * ifk);
		      float dbValue = 75 * (float)Math.log10(magnitude);
		      float testD  = (float) (Math.log10(magnitude - 0.699999988079071D));

		      float[] cartPoint = {
		          (float)(i * 32) / (mFFTBytes.length - 1),
		          2.0f / 2 - testD / 4
		      };

		      float[] polarPoint = toPolar(cartPoint);
		      mFFTPoints[i * 6] = polarPoint[0] - 1.0f;
		      mFFTPoints[i * 6 + 1] = polarPoint[1] - 1.0f;
		      mFFTPoints[i * 6 + 2] = 0;

		      float[] cartPoint2 = {
		          (float)(i * 32) / (mFFTBytes.length - 1),
		          2.0f / 2 + testD
		      };

		      float[] polarPoint2 = toPolar(cartPoint2);
		      mFFTPoints[i * 6 + 3] = polarPoint2[0] -1.0f ;
		      mFFTPoints[i * 6 + 4] = polarPoint2[1] -1.0f;
		      mFFTPoints[i * 6 + 5] = 0;
		    }
		    modulation += 0.02;
		    angleModulation += 0.015;
		 
    draw(gl);
	 }
    }

}

float modulation = 0;
float modulationStrength = 0.4f; // 0-1
float angleModulation = 0;
float aggresive = 0.4f;
private float[] toPolar(float[] cartesian)
{
  double cX = 2.0f/2;
  double cY = 2.0f/2;
  double angle = (cartesian[0]) * 2 * Math.PI;
  double radius = ((2.0f/2) * (1 - aggresive) + aggresive * cartesian[1]/2) * ((1 - modulationStrength) + modulationStrength * (1 + Math.sin(modulation)) / 2);
  float[] out = {
      (float)(cX + radius * Math.sin(angle + angleModulation)),
      (float)(cY + radius * Math.cos(angle + angleModulation))
  };
  return out;
}




Edit:
Quick extra question.
How do i make the background transparent?
I've been search on google for hours, but nothing works.
Again, sorry about all the questions.

Thanks in advance

This post has been edited by EndLessMind: 22 March 2013 - 02:46 AM

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3