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

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

posted @
2012-05-03 21:38 bennycen 閱讀(1373) |
評(píng)論 (1) |
編輯 收藏

2012年3月29日
摘要: 這兩題是單模式串匹配hdu2087 數(shù)據(jù)量較小,可以采用標(biāo)準(zhǔn)庫(kù)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 閱讀(1248) |
評(píng)論 (0) |
編輯 收藏
摘要: 也是一道AC自動(dòng)機(jī)解決多模式串匹配的問(wèn)題,注意的是用一個(gè)visited記錄id的出現(xiàn),以及病毒的數(shù)組需要排序,當(dāng)病毒數(shù)超過(guò)3時(shí)可以結(jié)束匹配。代碼如下:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> 1#include&nbs...
閱讀全文
posted @
2012-03-29 18:18 bennycen 閱讀(1273) |
評(píng)論 (0) |
編輯 收藏
摘要: AC自動(dòng)機(jī)用于多模式串匹配
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 閱讀(1264) |
評(píng)論 (0) |
編輯 收藏

2012年3月26日
Poj 2081
http://poj.org/problem?id=2081
求數(shù)列第i項(xiàng) 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
最長(zhǎng)公共串
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 對(duì)角
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 閱讀(934) |
評(píng)論 (0) |
編輯 收藏
摘要: 模擬題,不說(shuō)了
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 閱讀(1088) |
評(píng)論 (0) |
編輯 收藏

2012年3月22日
為AnyC添加了函數(shù)調(diào)用時(shí)的參數(shù)類型限制功能,可以限制改函數(shù)的某個(gè)參數(shù)的具體類型!
截圖如下:
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 閱讀(316) |
評(píng)論 (1) |
編輯 收藏

2012年3月12日
摘要: 數(shù)獨(dú)問(wèn)題采用跳舞鏈方法會(huì)得到比較快的速度用跳舞鏈解決的方法主要是將問(wèn)題的模型轉(zhuǎn)換成01覆蓋模型,然后模板之首先要了解它的限制條件:(1) 每一格只能填一個(gè)數(shù)字 (2) 每一列的數(shù)字是不同的(3) 每一行的數(shù)字是不同的(4) 每一個(gè)九宮格的數(shù)字是不同的那么我們可以構(gòu)造出一組狀態(tài):行狀態(tài)(i,j,k):表示第i行第j列填第k個(gè)數(shù)列狀態(tài)(i,j,k):表示第k個(gè)限制的子狀態(tài)為(i,j),子狀態(tài)根據(jù)限制而...
閱讀全文
posted @
2012-03-12 19:37 bennycen 閱讀(2041) |
評(píng)論 (3) |
編輯 收藏

2012年3月8日
摘要: 一、緣起一直很想做一個(gè)自己的動(dòng)態(tài)語(yǔ)言了,記得三年前學(xué)習(xí)Compiler的時(shí)候做了不成器的Tiny++和語(yǔ)法全部按足《編譯原理實(shí)踐》的C--,其中C--還做得非常不好(基本只能看看用不了),然后上次看了《游戲腳本高級(jí)編程》,里面介紹的XScript雖然非常簡(jiǎn)單,但已經(jīng)有語(yǔ)言的影子。然后又看了《python源碼剖析》,看了python的源碼,學(xué)習(xí)了很多python的內(nèi)部機(jī)理,感覺(jué)python雖強(qiáng)大巧妙...
閱讀全文
posted @
2012-03-08 11:05 bennycen 閱讀(709) |
評(píng)論 (4) |
編輯 收藏

2012年3月2日
前做了一個(gè)簡(jiǎn)單實(shí)用的本地程序評(píng)測(cè)機(jī),用作學(xué)校某比賽的評(píng)測(cè)(該比賽不是在線比賽,而是做完后自己發(fā)代碼然后我們自己手動(dòng)萍。。囧),該程序是一個(gè)本地評(píng)測(cè)系統(tǒng),用戶輸入單文件代碼或可執(zhí)行程序,和輸入數(shù)據(jù)和正確的輸出數(shù)據(jù),系統(tǒng)根據(jù)這些數(shù)據(jù)對(duì)代碼或程序進(jìn)行評(píng)測(cè)。
評(píng)測(cè)結(jié)果有:
Accept //通過(guò)
Compile Error //編譯錯(cuò)誤
Worng Answer //答案錯(cuò)誤
Time Limit Exceeded //超時(shí)
Memory Limit Exceeded //超內(nèi)存
Presentation Error //輸出格式錯(cuò)誤
System Error //系統(tǒng)錯(cuò)誤
下面簡(jiǎn)單聊聊實(shí)現(xiàn)的過(guò)程:
一、實(shí)現(xiàn)細(xì)節(jié)
1.1 編譯功能
類:CompilerHelper
函數(shù):static int compile(const std::string& sSourceFile, //源文件路徑
const std::string& sOutputFile);//執(zhí)行代碼路徑
流程如下:
生成編譯器輸入?yún)?shù)(編譯器路徑、文件路徑、包含路徑、庫(kù)路徑)在config.txt定義
-> 重定向in和out -> 創(chuàng)建進(jìn)程編譯->等待完畢后返回執(zhí)行結(jié)果
1.2 評(píng)測(cè)功能
需要獲得 執(zhí)行代碼路徑、輸入文件、期待輸出的答案文件、本次執(zhí)行程序的實(shí)際輸出文件、
時(shí)間、內(nèi)存、是不是SPJ
監(jiān)視器線程: 監(jiān)視進(jìn)程的執(zhí)行時(shí)間、使用內(nèi)存的信息
流程:
輸入信息-> 根據(jù)輸入文件產(chǎn)生輸入?yún)?shù)->創(chuàng)建進(jìn)程->監(jiān)視器開(kāi)啟->等待直到結(jié)束
->返回!=0?"System Error" : 記錄本次執(zhí)行所需要的時(shí)間和內(nèi)存->是否SPJ?啟動(dòng)spj比較器
:啟動(dòng)文件比較器
啟動(dòng)文件比較器: 比較實(shí)際的和答案的差異,完全相同的AC,只存在空格的差異為PE,其他情況的WA
spj比較器: 使用自己編寫的spj程序?qū)蓚€(gè)文件評(píng)測(cè)
1.3 測(cè)試套件
實(shí)現(xiàn)多個(gè)測(cè)試用例(多個(gè)輸入文件和輸出文件)
可以通過(guò)配置文件進(jìn)行配置
配置文件如下:
[TestSuite]
TestCaseCount=19 //用例個(gè)數(shù)
IsSpecialJudge=0 //是否SPJ
CodeFile=main.cpp //源文件,可設(shè)為NULL
SPJExe=lowSPJ.exe //SPJ路徑
ExecuteFile=NULL //如設(shè)置了就不啟用編譯功能
[TestCase_n] //第n個(gè)用例
TimeLimit=1000 //時(shí)間限制
MemoryLimit=65535 //內(nèi)存限制(KB)
StdInputFile=data1.txt //輸入文件
AnswerFile=output1.txt //答案
每個(gè)用例將new一個(gè)judgerunner實(shí)例
二、依賴庫(kù)
個(gè)人開(kāi)發(fā)的mtLibrary中的Common、Thread、Process庫(kù)模塊
三、運(yùn)行效果
配置文件示例
[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
這是運(yùn)行的效果,運(yùn)行后結(jié)果將保存帶JudgeResult.txt中

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