• Create Account

# tom_mai78101

Member Since 09 Jan 2007
Offline Last Active Mar 09 2014 08:35 AM

### This is what atan2() does if given two Vector2D points on 2D plane?

25 February 2014 - 03:44 AM

This is the basis of touch screen math calculations I'm working on. Just so happens, I tend to forget simple calculations. Especially where I don't even know the theta in the picture above is called? (The smaller angle of line and X-axis where the line intersects two arbitrarily given Vector2D points on a 2D plane? The atan2 angle?)

Anyway, I'm looking for the answer to the question: Is the theta the answer to atan2(Vector 1, Vector 2)?

### [SOLVED] How to modify FPS Camera Matrix into CounterStrike FPS Camera

20 February 2014 - 06:33 AM

Here's the current code that I've been tinkering over the past few days:

```public static void setFPSCamera(float[] matrix, int offset, float eyeX, float eyeY, float eyeZ, float pitch, float yaw, boolean isRadians)
{
//		if ( pitchDegrees<-90f)
//			pitchDegrees=-89.999999f;
//		if (pitchDegrees>90f)
//			pitchDegrees=89.999999f;
//		if (yawDegrees>360f)
//			yawDegrees=0f;
//		if (yawDegrees<0)
//			yawDegrees=360f;

}

float cosPitch=FloatMath.cos(pitch);
float sinPitch=FloatMath.sin(pitch);
float cosYaw=FloatMath.cos(yaw);
float sinYaw=FloatMath.sin(yaw);

Vector3f xAxis=new Vector3f(cosYaw, -sinPitch*sinYaw, -cosPitch*sinYaw);
Vector3f yAxis=new Vector3f(0, cosPitch, -sinPitch);
Vector3f zAxis=new Vector3f(sinYaw, sinPitch*cosYaw, cosPitch*cosYaw);
Vector3f eye=new Vector3f(eyeX, eyeY, eyeZ);

matrix[0+offset]=cosYaw;
matrix[1+offset]=0;
matrix[2+offset]=sinYaw;
matrix[3+offset]=0;

matrix[4+offset]=-sinPitch*sinYaw;
matrix[5+offset]=cosPitch;
matrix[6+offset]=sinPitch*cosYaw;
matrix[7+offset]=0;

matrix[8+offset]=-cosPitch*sinYaw;
matrix[9+offset]=-sinPitch;
matrix[10+offset]=cosPitch*cosYaw;
matrix[11+offset]=0;

matrix[12+offset]=-xAxis.dotProduct(eye);
matrix[13+offset]=-yAxis.dotProduct(eye);
matrix[14+offset]=-zAxis.dotProduct(eye);
matrix[15+offset]=1;
}```

The commented portion of the code is what I thought I'm trying to do.

When the camera is facing north, the pitch values work correctly.

But when the camera is facing in other directions, the pitch values aren't affected by rotation.

Can anyone give me a hint on what I need to do to modify this matrix? Thanks in advance.

### OpenGL ES 2.0: Text from TextView isn't showing up

17 February 2014 - 11:01 AM

I have adapted the code from Draw Text in OpenGL ES Android into my app, but the text isn't really showing up.

Here's what it currently looks like:

The green rectangle box is actually a Drawable bitmap.

I am expecting some sort of text, either white or black on top of the background, but nothing is ever showing up.

Here's the code for the Text class.

```package gl.es;

import java.nio.*;

import android.content.Context;
import android.graphics.*;
import android.graphics.drawable.Drawable;
import android.opengl.*;
import android.opengl.Matrix;

public class Text {

public int textTexture;
public FloatBuffer textFloatBuffer;
public FloatBuffer textureFloatBuffer;
public int bufferSize;

public int program;

private final int textWidth = 112;
private final int textHeight = 16;

//private float posX;

private int aTextPositionLocation;
private int aTexturePositionLocation;
private int uMatrixLocation;
private int uTextureUnitLocation;

public Text(Context context) {

program = Shader.buildProgram(context, R.raw.text_vert, R.raw.text_frag);

aTextPositionLocation = GLES20.glGetAttribLocation(program, "a_textPosition");
aTexturePositionLocation = GLES20.glGetAttribLocation(program, "a_texturePosition");
uMatrixLocation = GLES20.glGetUniformLocation(program, "u_matrix");
uTextureUnitLocation = GLES20.glGetUniformLocation(program, "u_textureUnit");

textTexture = createTexture(context);
setBuffer();

//posX = 0f;
}

public int createTexture(Context context) {
//Create empty mutable bitmap.
Bitmap bitmap = Bitmap.createBitmap(textWidth, textHeight, Bitmap.Config.ARGB_8888);
//Use Canvas to paint over it.
Canvas canvas = new Canvas(bitmap);
bitmap.eraseColor(0);

//Draw background
Drawable background = context.getResources().getDrawable(R.drawable.text_bg);
background.setBounds(0, 0, 112, 16);
background.draw(canvas);

//Draw text
Paint textPaint = new Paint();
textPaint.setTextSize(6f);
textPaint.setAntiAlias(false);
textPaint.setARGB(0xff, 0, 0, 0);
//Draw text centered.
canvas.drawText("Text.", 0, 0, textPaint);

int[] texture = new int[1];
GLES20.glGenTextures(1, texture, 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture[0]);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

//Recycle.
bitmap.recycle();
return texture[0];
}

public void setBuffer() {
final float[] vertexData = {
0f, 0f,
textWidth, 0f,
0f, textHeight,
0f, textHeight,
textWidth, 0f,
textWidth, textHeight
};

final float[] texData = {
0f, 1f,
1f, 1f,
0f, 0f,
0f, 0f,
1f, 1f,
1f, 0f
};

textFloatBuffer = ByteBuffer.allocateDirect(vertexData.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
textFloatBuffer.put(vertexData);
textureFloatBuffer = ByteBuffer.allocateDirect(texData.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
textureFloatBuffer.put(texData);
bufferSize = vertexData.length / 2;
}

public void transform(float[] model, float[] projection, float[] mvp) {
Matrix.setIdentityM(model, 0);
Matrix.translateM(model, 0, 0f, 0f, -60f);
Matrix.translateM(model, 0, -60f, 0f, 0f);
Matrix.multiplyMM(mvp, 0, projection, 0, model, 0);

//posX = (posX - 0.3f) % 112f;
}

public void setVertexPointers() {
textFloatBuffer.position(0);
GLES20.glVertexAttribPointer(aTextPositionLocation, 2, GLES20.GL_FLOAT, false, 2 * 4, textFloatBuffer);
GLES20.glEnableVertexAttribArray(aTextPositionLocation);
textFloatBuffer.position(0);
textureFloatBuffer.position(0);
GLES20.glVertexAttribPointer(aTexturePositionLocation, 2, GLES20.GL_FLOAT, false, 2 * 4, textureFloatBuffer);
GLES20.glEnableVertexAttribArray(aTexturePositionLocation);
textureFloatBuffer.position(0);
}

public void draw() {
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, bufferSize);
}

public void useProgram() {
GLES20.glUseProgram(program);
}

public void setUniforms(float[] matrix) {
GLES20.glUniformMatrix4fv(uMatrixLocation, 1, false, matrix, 0);
GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textTexture);
GLES20.glUniform1i(uTextureUnitLocation, 1);
}
}
```

Could someone tell me where I'm doing wrong? What should I do in order to fix this? Thanks in advance.

### When is Surface Pro 2 going to be on shelves in stores near me (international country?

16 February 2014 - 10:29 AM

There's no hint as to when Surface Pro 2 is coming, other than the fact that Microsoft didn't deliver them on the expected arrival date of 10/22/2013 here.

I'm not in US, so Surface Pro 2 isn't really available here. Curious link for those uninitiated.

And no one here is breaking the ice on the info and stuff. All I get on Google are old articles reporting/reviewing the 1st-gen Surface Pro.

Sigh.

### FPS Camera calculations problem

13 February 2014 - 06:23 AM

I got this information below from a blog that explains the view matrix and its properties.

To make a FPS camera, I can use one view matrix, the pitch, and the yaw.

By obtaining the eye coordinate in the 3D world, I can use the following pseudocode to create the view matrix:

```yaw.toRadians()

Vec3 xAxis = {cos(yaw), -sin(pitch)*sin(yaw), -cos(pitch)*sin(yaw)}
Vec3 yAxis = {0, cos(pitch), -sin(pitch)}
Vec3 zAxis = {sin(yaw), sin(pitch)*cos(yaw), cos(pitch)*cos(yaw)}

viewMatrix = {
xAxis.x, yAxis.y, zAxis.x, 0,
xAxis.y, yAxis.y, zAxis.y, 0,
xAxis.z, yAxis.y, zAxis.z, 0,
-dot(xAxis, eye), -dot(yAxis, eye), -dot(zAxis, eye), 1
}

```

However, when I try to implement this in my code, I get weird results:

I can't turn left and right correctly to see the entire green rectangle box. I can look up and down, but the view would get distorted and revolves around my head like a planet revolving around a star. My view is stuck facing at a specific field of view, and I don't know why.

My eye vector is {0, 0, 40f}.

The green rectangular box is 112 wide, 16 high. When looked upon from the eye position, I should be able to see all of the box.

I don't really know how to fix this. How do I turn and look up/down properly?

PARTNERS