gluPerspective & gluLookAt Implementation in Android NDK
There is no glu libraries for android ndk, so I need re-implement one for it. After some time research, I grab some ideas and re-implement glPerspective and gluLookAt function. Both of them works pretty well on PC and android.
gluPerspective Implementation
void xgluPerspective( float fovy, float aspect, float near_clip, float far_clip ) { const double PI = 3.1415926; double TWOPI_OVER_360 = 2.0 * PI / 360.0; float half_height = near_clip * (float)tan( fovy * 0.5 * TWOPI_OVER_360 ); float half_width = half_height * aspect; #ifdef WIN32 glFrustum( -half_width, half_width, -half_height, half_height, near_clip, far_clip ); #elif defined(CK_ANDROID) glFrustumf( -half_width, half_width, -half_height, half_height, near_clip, far_clip ); #endif }
gluLookAt Implementation
void xgluLookAt ( float eyex, float eyey, float eyez, float centerx, float centery, float centerz, float upx, float upy, float upz) { vector3_t forward(centerx - eyex, centery - eyey, centerz - eyez); vector3_t up(upx, upy, upz); forward.Normalize(); vector3_t side = forward ^ up; side.Normalize(); up = side ^ forward; float m[4][4]; m[0][0] = side[0]; m[1][0] = side[1]; m[2][0] = side[2]; m[3][0] = 0.0f; m[0][1] = up[0]; m[1][1] = up[1]; m[2][1] = up[2]; m[3][1] = 0.0f; m[0][2] = -forward[0]; m[1][2] = -forward[1]; m[2][2] = -forward[2]; m[3][2] = 0.0f; m[0][3] = 0.0f; m[1][3] = 0.0f; m[2][3] = 0.0f; m[3][3] = 1.0f; glMultMatrixf(&m[0][0]); glTranslatef(-eyex, -eyey, -eyez); }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了