3D编程技巧与OpenGL ES光照
在3D编程中,有许多实用的技巧和特性可以提升游戏的视觉效果。本文将介绍3D向量距离计算以及OpenGL ES中的光照模型。
1. 3D向量距离计算
在3D编程里,常常需要计算两个向量之间的距离。以下是相关的方法实现:
public float dist(Vector3 other) {
float distX = this.x - other.x;
float distY = this.y - other.y;
float distZ = this.z - other.z;
return FloatMath.sqrt(distX * distX + distY * distY + distZ * distZ);
}
public float dist(float x, float y, float z) {
float distX = this.x - x;
float distY = this.y - y;
float distZ = this.z - z;
return FloatMath.sqrt(distX * distX + distY * distY + distZ * distZ);
}
public float distSquared(Vector3 other) {
float distX = this.x - other.x;
float distY = this.y - other.y;
float distZ = this.z - other.z;
return di