2011-08-22 27 views
9

最后,我决定把我自己的WebGL 3D引擎从地上爬起来,我开始从教程和http://www.khronos.org/webgl/http://learningwebgl.comhttps://developer.mozilla.org/en/WebGL在glMatrix,Sylvester和CanvasMatrix之间进行选择?

但问题是,使用/每个教程推荐不同的库矩阵计算,所以我困惑!

  • Khronos的建议CanvasMatrix(但现在他们改用J3DI.js从苹果?)
  • Mozilla的建议西尔维斯特一路走好!
  • Learningwebgl.com建议glMatrix

问题是:哪一个是非常适合3D WebGL的应用,图表和游戏? (无论是性能和可用性问题)

感谢

回答

7

http://glmatrix.googlecode.com/hg/benchmark/matrix_benchmark.html

我用glMatrix,并能正常工作。这个API有点奇怪。

var in = vec3.create([1, 2, 3]); 

//overwrite 'in' in-place 
vec3.scale(in, 2); 

//write output to a different vector 
var out = vec3.create(); 
vec3.scale(in, 2, out); 

或为glMatrix 2

var in = vec3.fromValues(1, 2, 3); 

//overwrite 'in' in-place 
vec3.scale(in, in, 2); 

//write output to a different vector 
var out = vec3.create(); 
vec3.scale(out, in, 2); 

但是,它的速度快,它支持我想要的操作,这是简单的。来源可以理解。

虽然我没有与其他人的经验。

更新:

有更多的图书馆的基准可在http://stepheneb.github.com/webgl-matrix-benchmarks/matrix_benchmark.html。在我的Mac上的Chrome中,Closure非常轻松地胜出。在我个人电脑上的Chrome浏览器中,它更像是一种折腾。我现在仍然在使用glMatrix,因为它生活在一个单独的Javascript文件中。

+0

很遗憾,他们没有针对numeric.js和Sylvester进行基准测试。根据[numeric.js基准测试](http://www.numericjs.com/benchmark.html),至少在我的系统上,Sylvester实际上比3x3(及更高版本)的Google Closure速度更快,至少在我的系统上(WinXP/32与Chrome 20)。 – feklee

+1

我[只是添加了Sylvester](https://github.com/feklee/webgl-matrix-benchmarks)到基准测试(pull request pending)。西尔维斯特是*慢*。为什么它比[数字Javascript基准测试](http://www.numericjs.com/benchmark.html)中的Closure更快?答案:该基准测试Closure的通用矩阵函数,而不是那些专用于WebGL的函数。 – feklee

+1

好吧,在glMatrix 2.2.0中vec3.create不带参数,如下所示创建一个将创建一个零长度的vec3,但vec3.fromValues(1,2,3)将工作 – Octopus

相关问题