1. 凹凸紋理映射
凹凸紋理存放在一個紋理圖片中,其(R,G,B)分別對應(u,v,w)的normalize向量,由于(R,G,B)的歸一化后的范圍是(0-1),故要通過(x - 0.5)*2轉換成(-1,1)的范圍。
另外,由于凹凸紋理記錄的是針對一個垂直于視線的平面的向量,如果將其貼到其他物體上,如環體,球體,就必須計算紋理坐標空間,就是將不垂直于視線的變換為垂直于視線的。可以構造渲染object的(法線,切線),并且得垂直于法線切線的向量,構成坐標系,然后計算光線方向lightDir和視線方向viewDir時,要將其變換到紋理空間坐標系去。
最后在pixel shader中根據lightDir、viewDir和texcoord,像一般光照計算那樣計算,只不過其“法向量”由凹凸紋理提供。
2. 立方體環境映射
先構造立方體紋理,CubeMap,像個紙盒打開6個面那樣。然后逐頂點計算反射向量,計算如下:R = I - 2*N*dot(I,N),然后在pixel shader中texCUBE。

3.折射反射
在2中再添加一個折射向量,然后pixel shader中兩次texCUBE后混合一下。

posted @
2012-05-03 21:38 bennycen 閱讀(1374) |
評論 (1) |
編輯 收藏
摘要: 這兩題是單模式串匹配hdu2087 數據量較小,可以采用標準庫strstr輕松完成
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> 1#include <stdio.h> 2#include &...
閱讀全文
posted @
2012-03-29 20:13 bennycen 閱讀(1249) |
評論 (0) |
編輯 收藏
摘要: 也是一道AC自動機解決多模式串匹配的問題,注意的是用一個visited記錄id的出現,以及病毒的數組需要排序,當病毒數超過3時可以結束匹配。代碼如下:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> 1#include&nbs...
閱讀全文
posted @
2012-03-29 18:18 bennycen 閱讀(1273) |
評論 (0) |
編輯 收藏
摘要: AC自動機用于多模式串匹配
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> 1#include <stdio.h> 2#include <string.h>&n...
閱讀全文
posted @
2012-03-29 18:15 bennycen 閱讀(1265) |
評論 (0) |
編輯 收藏
Poj 2081
http://poj.org/problem?id=2081
求數列第i項 0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9
解法:按照題目要求遞推即可
#include <stdio.h>
#include <string.h>
bool visited[4000005];
int nums[4000005];
void pre()
{
memset(visited,0,sizeof(visited));
memset(nums,0,sizeof(nums));
visited[0] = true;
for (int i = 1; i <= 500000; ++i)
{
int k = nums[i-1] - i;
if (k <=0 || visited[k])
{
nums[i] = nums[i-1] + i;
visited[nums[i]] = true;
}
else
{
nums[i] = nums[i-1] - i;
visited[nums[i]] = true;
}
}
}
int main()
{
pre();
int n;
while(scanf("%d",&n) != EOF)
{
if (n == -1)
{
break;
}
printf("%d\n",nums[n]);
}
return 0;
}
2250
http://poj.org/problem?id=2250
最長公共串
1 #include <iostream>
2 #include <string.h>
3 #include <string>
4 #include <vector>
5 using namespace std;
6
7 string strs1[128];
8 int len1;
9 string strs2[128];
10 int len2;
11 int dp[128][128];
12 int flags[128][128];//1 上 2 左 3 對角
13
14 void Test()
15 {
16 memset(dp,0,sizeof(dp));
17 memset(flags,0,sizeof(flags));
18 for (int i = 1; i <= len1; ++i)
19 {
20 for (int j = 1; j <= len2; ++j)
21 {
22 if (strs1[i] == strs2[j])
23 {
24 dp[i][j] = dp[i-1][j-1] + 1;
25 flags[i][j] = 3;
26 }
27 else
28 {
29 int m1 = dp[i-1][j];
30 int m2 = dp[i][j-1];
31 if (m1 < m2)
32 {
33 dp[i][j] = m2;
34 flags[i][j] = 2;
35 }
36 else
37 {
38 dp[i][j] = m1;
39 flags[i][j] = 1;
40 }
41 }
42 }
43 }
44 int pos1 = len1;
45 int pos2 = len2;
46 vector<string> vec;
47 while(true)
48 {
49 if (flags[pos1][pos2] == 3)
50 {
51 vec.push_back(strs1[pos1]);
52 --pos1;
53 --pos2;
54 }
55 else if (flags[pos1][pos2] == 2)
56 {
57 --pos2;
58 }
59 else if (flags[pos1][pos2] == 1)
60 {
61 --pos1;
62 }
63 else
64 break;
65 }
66 for (int i = vec.size()-1; i >=0 ; --i)
67 {
68 cout << vec[i];
69 if (i == 0)
70 {
71 cout << endl;
72 }
73 else
74 {
75 cout << " ";
76 }
77 }
78 }
79
80 int main()
81 {
82 //freopen("data.txt","r",stdin);
83 string input;
84 int k = 0;
85 len1 = len2 = 0;
86 while(cin >> input)
87 {
88 if (input == "#")
89 {
90 if (k == 1)
91 {
92 Test();
93 k = 0;
94 len1 = len2 = 0;
95 continue;
96 }
97 else
98 {
99 k = 1;
100 }
101 }
102 if (k == 0)
103 {
104 strs1[++len1] = input;
105 }
106 else
107 {
108 strs2[++len2] = input;
109 }
110 }
111 return 0;
112 }
posted @
2012-03-26 20:19 bennycen 閱讀(935) |
評論 (0) |
編輯 收藏
摘要: 模擬題,不說了
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> 1#include <stdio.h> 2#include <string.h> 3 4char&n...
閱讀全文
posted @
2012-03-26 10:42 bennycen 閱讀(1089) |
評論 (0) |
編輯 收藏
為AnyC添加了函數調用時的參數類型限制功能,可以限制改函數的某個參數的具體類型!
截圖如下:
1 function check(<int> k,j)
2 {
3 print(j + k + "\n");
4 }
5
6 //check("world","hello");
7
8 function add(<int> a)
9 {
10 return function ( b)
11 {
12 return a+b;
13 }
14 }
15
16 class Test
17 {
18 public:
19 function add(<int> a, b)
20 {
21 return a+b;
22 }
23 }
24
25 var k = Test();
26 print(k.add(1,2) + "\n");
27
28 function ppp(<array> arrs,<int> _index)
29 {
30 return arrs[_index];
31 }
32
33 var ks = [1,2,3,4,5];
34 ppp(ks,1);
35
36 function testValue(<value> _v)
37 {
38 print(_v+"\n");
39 }
40 testValue(1);
41 testValue(1.2);
42 testValue("sss");
43 testValue(false);
44
45 function testFunc(<function> _f,_v)
46 {
47 return _f(_v);
48 }
49
50 var f1 = add(40);
51 print(testFunc(f1,2) + "\n");
posted @
2012-03-22 22:14 bennycen 閱讀(317) |
評論 (1) |
編輯 收藏
摘要: 數獨問題采用跳舞鏈方法會得到比較快的速度用跳舞鏈解決的方法主要是將問題的模型轉換成01覆蓋模型,然后模板之首先要了解它的限制條件:(1) 每一格只能填一個數字 (2) 每一列的數字是不同的(3) 每一行的數字是不同的(4) 每一個九宮格的數字是不同的那么我們可以構造出一組狀態:行狀態(i,j,k):表示第i行第j列填第k個數列狀態(i,j,k):表示第k個限制的子狀態為(i,j),子狀態根據限制而...
閱讀全文
posted @
2012-03-12 19:37 bennycen 閱讀(2045) |
評論 (3) |
編輯 收藏
摘要: 一、緣起一直很想做一個自己的動態語言了,記得三年前學習Compiler的時候做了不成器的Tiny++和語法全部按足《編譯原理實踐》的C--,其中C--還做得非常不好(基本只能看看用不了),然后上次看了《游戲腳本高級編程》,里面介紹的XScript雖然非常簡單,但已經有語言的影子。然后又看了《python源碼剖析》,看了python的源碼,學習了很多python的內部機理,感覺python雖強大巧妙...
閱讀全文
posted @
2012-03-08 11:05 bennycen 閱讀(710) |
評論 (4) |
編輯 收藏
前做了一個簡單實用的本地程序評測機,用作學校某比賽的評測(該比賽不是在線比賽,而是做完后自己發代碼然后我們自己手動萍。。囧),該程序是一個本地評測系統,用戶輸入單文件代碼或可執行程序,和輸入數據和正確的輸出數據,系統根據這些數據對代碼或程序進行評測。
評測結果有:
Accept //通過
Compile Error //編譯錯誤
Worng Answer //答案錯誤
Time Limit Exceeded //超時
Memory Limit Exceeded //超內存
Presentation Error //輸出格式錯誤
System Error //系統錯誤
下面簡單聊聊實現的過程:
一、實現細節
1.1 編譯功能
類:CompilerHelper
函數:static int compile(const std::string& sSourceFile, //源文件路徑
const std::string& sOutputFile);//執行代碼路徑
流程如下:
生成編譯器輸入參數(編譯器路徑、文件路徑、包含路徑、庫路徑)在config.txt定義
-> 重定向in和out -> 創建進程編譯->等待完畢后返回執行結果
1.2 評測功能
需要獲得 執行代碼路徑、輸入文件、期待輸出的答案文件、本次執行程序的實際輸出文件、
時間、內存、是不是SPJ
監視器線程: 監視進程的執行時間、使用內存的信息
流程:
輸入信息-> 根據輸入文件產生輸入參數->創建進程->監視器開啟->等待直到結束
->返回!=0?"System Error" : 記錄本次執行所需要的時間和內存->是否SPJ?啟動spj比較器
:啟動文件比較器
啟動文件比較器: 比較實際的和答案的差異,完全相同的AC,只存在空格的差異為PE,其他情況的WA
spj比較器: 使用自己編寫的spj程序對兩個文件評測
1.3 測試套件
實現多個測試用例(多個輸入文件和輸出文件)
可以通過配置文件進行配置
配置文件如下:
[TestSuite]
TestCaseCount=19 //用例個數
IsSpecialJudge=0 //是否SPJ
CodeFile=main.cpp //源文件,可設為NULL
SPJExe=lowSPJ.exe //SPJ路徑
ExecuteFile=NULL //如設置了就不啟用編譯功能
[TestCase_n] //第n個用例
TimeLimit=1000 //時間限制
MemoryLimit=65535 //內存限制(KB)
StdInputFile=data1.txt //輸入文件
AnswerFile=output1.txt //答案
每個用例將new一個judgerunner實例
二、依賴庫
個人開發的mtLibrary中的Common、Thread、Process庫模塊
三、運行效果
配置文件示例
[TestSuite]
TestCaseCount=19
IsSpecialJudge=0
CodeFile=main.cpp
SPJExe=NULL
[TestCase_1]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data1.txt
AnswerFile=output1.txt
[TestCase_2]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data2.txt
AnswerFile=output2.txt
[TestCase_3]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data3.txt
AnswerFile=output3.txt
[TestCase_4]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data4.txt
AnswerFile=output4.txt
[TestCase_5]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data5.txt
AnswerFile=output5.txt
[TestCase_6]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data6.txt
AnswerFile=output6.txt
[TestCase_7]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data7.txt
AnswerFile=output7.txt
[TestCase_8]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data8.txt
AnswerFile=output8.txt
[TestCase_9]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data9.txt
AnswerFile=output9.txt
[TestCase_10]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data10.txt
AnswerFile=output10.txt
[TestCase_11]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data11.txt
AnswerFile=output11.txt
[TestCase_12]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data12.txt
AnswerFile=output12.txt
[TestCase_13]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data13.txt
AnswerFile=output13.txt
[TestCase_14]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data14.txt
AnswerFile=output14.txt
[TestCase_15]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data15.txt
AnswerFile=output15.txt
[TestCase_16]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data16.txt
AnswerFile=output16.txt
[TestCase_17]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data17.txt
AnswerFile=output17.txt
[TestCase_18]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data18.txt
AnswerFile=output18.txt
[TestCase_19]
TimeLimit=1000
MemoryLimit=65535
StdInputFile=data19.txt
AnswerFile=output19.txt
這是運行的效果,運行后結果將保存帶JudgeResult.txt中

posted @
2012-03-02 20:30 bennycen 閱讀(341) |
評論 (1) |
編輯 收藏