Re: [心得] Webgl+Js的Spa

看板Soft_Job作者 (3d)時間5年前 (2019/03/31 22:50), 編輯推噓1(100)
留言1則, 1人參與, 5年前最新討論串2/2 (看更多)
之前說typedarray不好用,因為subarray出來的view其實很昂貴,整個記憶體使用量爆增。但因http://glmatrix.net/ 的library的api需要這樣,我又不想重寫。 現在有個solution分享一下。我加了類似下面這樣的程式。 Object.defineProperties(Vertex.prototype, { 0: { get: function() {return Vertex.position[this.posOffset];}, set: function(value) {Vertex.position[this.posOffset] = value;} }, 1: { get: function() {return Vertex.position[this.posOffset+1];}, set: function(value) {Vertex.position[this.posOfset+1] = value;} }, 2: { get: function() {return Vertex.position[this.posOffset+2];}, set: function(value) {Vertex.position[this.posOffset+2] = value;} } }); 是的,Javascript可以有數字的member。但只能vertex[0]這樣access,不能vertex.1。 glmatrix的api,vec3使用array[0], [1],[2]。所以我就define, 0, 1, 2的member。這樣就不用subarray出一個float32array(3)的東東。 這算是duck typing, 比class, inheritance更接近Alan Kay,oop之父,定義的oop http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/doc_kay_oop_en Dr. Alan Kay在這email裡把OOP定義清楚。我們所了解的OOP是從Simula 67來的,因c++而普及,其實並不是Alan Kay的OOP。 他的定義是寫在最後 "OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I'm not aware of them." -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.227.164.111 ※ 文章網址: https://www.ptt.cc/bbs/Soft_Job/M.1554043816.A.1AF.html

04/01 09:23, 5年前 , 1F
04/01 09:23, 1F
文章代碼(AID): #1SeDEe6l (Soft_Job)
文章代碼(AID): #1SeDEe6l (Soft_Job)