最近在思考若是要作個遙控的箱子,應該長什麼樣子,不過呢,先來看看大家都是怎麼作的。這些大多是軍用的,蠻適合我們身為退伍軍人研究單位的風格啊!
2012/05/25
2012/05/17
C# game programming - For Serious Game Creation
有用的Timer
using System.Runtime.InteropServices;
namespace GameLoop {
public class PreciseTimer {
[System.Security.SuppressUnmanagedCodeSecurity] [DllImport("kernel32")] private static extern bool QueryPerformanceFrequency(ref long
PerformanceFrequency); [System.Security.SuppressUnmanagedCodeSecurity] [DllImport("kernel32")] private static extern bool QueryPerformanceCounter(ref long PerformanceCount); long _ticksPerSecond = 0; long _previousElapsedTime = 0; public PreciseTimer() {
QueryPerformanceFrequency(ref _ticksPerSecond); GetElapsedTime(); // Get rid of first rubbish result
} public double GetElapsedTime() {
long time = 0; QueryPerformanceCounter(ref time); double elapsedTime = (double)(time - _previousElapsedTime) /
(double)_ticksPerSecond; _previousElapsedTime = time; return elapsedTime;
} }
}
The QueryPerformanceFrequency function retrieves the frequency of the high-resolution performance counter. Most modern hardware has a high- resolution timer; this function is used to get the frequency at which the timer increments. The QueryPerformanceCounter function retrieves the current value of the high-resolution performance counter. These can be used together to time how long the last frame took.
GetElapsedTime should be called once per frame and this will keep track of the time. The elapsed time is so important that it should be incorporated into the game loop. Open the Program.cs file and change the game loop so it takes one argument.
public class FastLoop {
PreciseTimer _timer = new PreciseTimer(); public delegate void LoopCallback(double elapsedTime);
The timer is then called once per frame and elapsed time is passed on to FastLoop’s callback.
void OnApplicationEnterIdle(object sender, EventArgs e) {
while (IsAppStillIdle()) {
_callback(_timer.GetElapsedTime()); }
}
The game loop can now be used to smoothly animate any game! By the end of this chapter, the game loop will be used to smoothly rotate a 3D triangle—the ‘‘Hello World’’ application of OpenGL programming.
2011/10/31
2011/10/13
Working with ROS and OpenCV 在ROS裡面用OpenCV
這個印度人的部落格介紹了不少ROS與OpenCV的東西,先來試試看這個。
http://siddhantahuja.wordpress.com/2011/07/20/working-with-ros-and-opencv-draft/
http://siddhantahuja.wordpress.com/2011/07/20/working-with-ros-and-opencv-draft/
2011/07/26
How to import kivy in Eclipse 如何在Eclipse中加入Kivy的套件
今天查了下Python的資料,看到一個不錯的套件Kivy,可是呢,網站上的資料都只有英文不說,連如何加到Eclipse裡也沒有。難道我得要每次都拖拉我的程式到Kivy中執行嗎?這太麻煩了啊!
在網路上搜尋了一下,沒有人做過這件事,唯一的一個官方討論區的建議是,大部份的Kivy開發者都用小作家類得文字編輯器,在命令模式下執行。雖然我也很享受在鍵盤上敲打然後程式跑出來的感覺,可是呢,總是不甘心好不容易裝了個Eclipse+PyDev卻不能在上面用Kivy,最後花了點時間東看看西找找,居然也被我弄出來了,為了紀念這麼一天,在此紀錄一下。
在Mac OS X下的做法,首先用Terminal執行以下的命令。用來找出到底kivy躲在哪裡。
$ which kivy
我的電腦幫我找出來他在這裡的目錄內。
/usr/local/bin/kivy
輸入剛才找到的目錄,取個名字叫做kivy。
最後呢,他會幫忙找出這些,我加選了出現kivy的那兩個,其他是電腦自行找出來的。
之後選取Apply,當然,別忘記在Project->Property中選用新作的Interpreter。
最後,再重新啓動Eclipse就可以用囉!測試一下Hello World程式,完全沒有錯誤了。
import kivy
kivy.require('1.0.6') # replace with your current kivy version !
from kivy.app import App
from kivy.uix.button import Button
class MyApp(App):
def build(self):
return Button(text='Hello World')
if __name__ in ('__android__', '__main__'):
MyApp().run()
結論,這可能是太簡單了,所以沒有人作成教學放在網路上。不過呢,對於我這種程式菜鳥,還是得靠這種圖文教學才學得會。若有其他人也有同樣的困擾,希望這篇對他有些幫助。
在網路上搜尋了一下,沒有人做過這件事,唯一的一個官方討論區的建議是,大部份的Kivy開發者都用小作家類得文字編輯器,在命令模式下執行。雖然我也很享受在鍵盤上敲打然後程式跑出來的感覺,可是呢,總是不甘心好不容易裝了個Eclipse+PyDev卻不能在上面用Kivy,最後花了點時間東看看西找找,居然也被我弄出來了,為了紀念這麼一天,在此紀錄一下。
在Mac OS X下的做法,首先用Terminal執行以下的命令。用來找出到底kivy躲在哪裡。
$ which kivy
我的電腦幫我找出來他在這裡的目錄內。
/usr/local/bin/kivy
輸入剛才找到的目錄,取個名字叫做kivy。
最後呢,他會幫忙找出這些,我加選了出現kivy的那兩個,其他是電腦自行找出來的。
之後選取Apply,當然,別忘記在Project->Property中選用新作的Interpreter。
最後,再重新啓動Eclipse就可以用囉!測試一下Hello World程式,完全沒有錯誤了。
import kivy
kivy.require('1.0.6') # replace with your current kivy version !
from kivy.app import App
from kivy.uix.button import Button
class MyApp(App):
def build(self):
return Button(text='Hello World')
if __name__ in ('__android__', '__main__'):
MyApp().run()
結論,這可能是太簡單了,所以沒有人作成教學放在網路上。不過呢,對於我這種程式菜鳥,還是得靠這種圖文教學才學得會。若有其他人也有同樣的困擾,希望這篇對他有些幫助。
Subscribe to:
Posts (Atom)