Android Opengl顶点大于1
我在安卓中做一个多边形,我有一个顶点,问题是,有一些大于1的顶点,它们是浮点数 我见过一段代码,其中1的值是这样处理的:Android Opengl顶点大于1,android,opengl,Android,Opengl,我在安卓中做一个多边形,我有一个顶点,问题是,有一些大于1的顶点,它们是浮点数 我见过一段代码,其中1的值是这样处理的: int one = 0x10000; 我有如下浮动值: float verticesflotantes[]={//Arreglo de Vertices Flotantes 1.0000f, 1.0000f, 4.2361f, 1.0000f, 1.0000f, -4.2361f,
int one = 0x10000;
我有如下浮动值:
float verticesflotantes[]={//Arreglo de Vertices Flotantes
1.0000f, 1.0000f, 4.2361f,
1.0000f, 1.0000f, -4.2361f,
1.0000f, -1.0000f, 4.2361f,
1.0000f, -1.0000f, -4.2361f,
-1.0000f, 1.0000f, 4.2361f,
-1.0000f, 1.0000f, -4.2361f,
-1.0000f, -1.0000f, 4.2361f,
-1.0000f, -1.0000f, -4.2361f,
4.2361f, 1.0000f, 1.0000f,.... continue...
但是我需要的顶点数组是一个int,我试着这样做:
int vertices[] = new int[verticesflotantes.length];
for(int i = 0;i<verticesflotantes.length;i++){
// 1 = 65536
// 5 = 1 = 65536
// 5 = 65536
// x = x*65536/5
float regla3 = verticesflotantes[i]*65536/5;
String hexadecimal = Float.toHexString(regla3);
vertices[i]= Integer.parseInt(hexadecimal,16);
}
int顶点[]=新的int[verticesflotantes.length];
对于(int i=0;i您得到了NumberFormatException,因为您在Integer.parseInt(…)
函数中解析了一个“浮点字符串”。
也许你可以这样做:
int regla3 = (int) verticesflotantes[i]*65536/5; // get the integer part
// well... now you have integer part, I think there is nothing we need to do.
vertices[i] = regla3;