- 积分
- 136115
- 注册时间
- 2014-12-27
- 最后登录
- 2024-3-28
- 在线时间
- 602 小时
- 威望
- 562
- 贡献
- 29
- 金币
- 52619
- 钢镚
- 1422
- 交易凭证
- 1
- 分享
- 0
- 精华
- 33
- 帖子
- 2094
- 主题
- 1742
TA的每日心情 | 擦汗 2018-4-10 15:18 |
---|
签到天数: 447 天 [LV.9]以坛为家II
超级版主
- 威望
- 562
- 贡献
- 29
- 金币
- 52619
- 钢镚
- 1422
|
Crossbridge = FlasCC = Alchemy
接續上一篇Crossbridge sample 02 Interop
這篇來講講範例 3 Drawing。
如果是用 Java 32 的話,先修改D:\Crossbridge_1.0.1\samples\03_Drawing內的Makefile在5行的後面輸入 -jvmopt=-Xmx1G
運行D:\Crossbridge_1.0.1內的run.bat,並輸入cd 03_Drawing,再輸入make,等了27秒
會編譯voronoi.cpp和VoronoiDiagramGenerator.cpp成一個voronoi.swf檔案
運行voronoi.swf
開兩個 voronoi.swf ,發現產生的圖竟然是一樣的,就算重先編譯還是根本來的一樣。果然 C 語言亂數是偽亂數。
讓我們來分析一下 C++ 程式碼,niauwu 順便翻譯一下註釋,並註釋之好了,歡迎加入譯林軍
名詞解釋
- voronoi 沃羅諾伊圖
由俄國數學家Georgy Fedoseevich Voronoi 建立的空間分割演算法。 - CMoudle C語言程式模組
Contains convenience functions for reading and writting to domainMemory; also manages any flascc-specific global state (for example, the VFS and Posix interface implementations.)
CMoudle 包涵方便的函數,用來讀寫主要記憶體; 也管理任何 flascc 相關的全域狀態(例如,VFS 和 Posix 介面實現)
詳見幫助文檔 D:/Crossbridge_1.0.1/README.html > AS3 API Reference > com.adobe.flascc > CModule - rootSprite 根Sprite
A reference to the current rootSprite so that flascc code has an easy way of getting to the stage regardless of what preloaders might be employed.
目前 rootSprite 的參考,以便 flascc 代碼不論 preloader 空與否,都可以輕易的獲得 stage。
詳見幫助文檔 D:/Crossbridge_1.0.1/README.html > AS3 API Reference > com.adobe.flascc > CModule > rootSprite - gfx graphics 的縮寫
應該是因為 ph 發音為 f、cs 發音為 x - rand()
C 語言亂數函數,傳回一個介於 0 到 RAND_MAX 之間的一個數 - RAND_MAX
stdlib.h 定義的一個常數,其值在不同的系統有不同的大小,以 DOS 系統為例,其值為 32767 (215-1)。
分析voronoi.cpp
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- #include "VoronoiDiagramGenerator.h"
- #include "AS3/AS3.h"
-
- int main(int argc,char **argv)
- {
- int stagewidth, stageheight;
-
- inline_as3(
- "import flash.display.Stage;\n"
- "import flash.display.Graphics;\n"
- "import com.adobe.flascc.CModule;\n"
- "var gfx = CModule.rootSprite.graphics;\n"
- "gfx.lineStyle(1, 0);\n" // 等同 AS3 graphics.lineStyle(1, 0);
- "gfx.beginFill(0, 0.0);\n" // 等同 AS3 graphics.beginFill(0, 0.0);
- "%0 = CModule.rootSprite.stage.stageWidth;\n" // %0獲得舞台寬度
- "%1 = CModule.rootSprite.stage.stageHeight;\n" // %1獲得舞台高度
- : "=r"(stagewidth),"=r"(stageheight) : //%0為stagewidth,%1為stageheight
- );
-
- const int cellcount = 512; // 欄位數量
- float xvals[cellcount], yvals[cellcount]; // x和y變數單精度浮點數陣列
- for(int i=0; i<cellcount; i++) {
- xvals[i] = stagewidth * ((float)rand()/(float)RAND_MAX); // 獲得0~1之間的亂數*舞台寬度,指定給xvals[i]
- yvals[i] = stageheight * ((float)rand()/(float)RAND_MAX); // 獲得0~1之間的亂數*舞台寬度,指定給yvals[i]
- }
-
- VoronoiDiagramGenerator vdg; //創建VoronoiDiagramGenerator實例vdg
- vdg.generateVoronoi(xvals, yvals, cellcount, 0, stagewidth, 0, stageheight, 3); // 產生Voronoi
- vdg.resetIterator(); //重設Iterator
-
- float x1,y1,x2,y2;
- while(vdg.getNext(x1,y1,x2,y2))
- {
- inline_as3("gfx.moveTo(%0,%1);\n" : : "r"(x1), "r"(y1)); // 等同 AS3 graphics.moveTo(x1, y1);
- inline_as3("gfx.lineTo(%0,%1);\n" : : "r"(x2), "r"(y2)); // 等同 AS3 graphics.lineTo(x2, y2);
- }
- inline_as3("gfx.endFill();\n"); // 等同 AS3 graphics.endFill();
- }
复制代码 VoronoiDiagramGenerator.cpp 和 VoronoiDiagramGenerator.h 就不分析了,因為那不是重點,重點是VoronoiDiagramGenerator.cpp include VoronoiDiagramGenerator.h ,然後 voronoi.cpp include VoronoiDiagramGenerator.cpp 和 AS3/AS3.h 和 stdlib.h ,並用 stdlib.h 的 rand()函數取得亂數,紀錄為x、y變數陣列,傳進VoronoiDiagramGenerator,獲得x1,y1,x2,y2,再用 AS3/AS3.h 畫出 Voronoi 圖。
本例就是要講調用已有的 c++ 演算法代碼,和 AS3.h 畫出 Voronoi 圖。
本文来自:http://bbs.9ria.com/thread-417600-1-1.html
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|