Play Like Designer part1 :http://penny-arcade.com/patv/episode/playing-like-a-designer-pt.-1
Play Like Designer part2:http://penny-arcade.com/patv/episode/playing-like-a-designer-pt.-2
Don't Know what is mechanics :http://penny-arcade.com/patv/episode/narrative-mechanics
All reference and link from: Penny Arcade - Extra Credits
Wednesday, January 4, 2012
Wednesday, November 30, 2011
DirectX-Draw Triangle Note
There three main function need to be use.
Its do :
1.Loaded And Compiled with two shader
2.Create Object for each one
3.Set the two object
2.
Global
It do:
1.Create three vertex with both position
2.Create vertex buffer object
3.Copied the vertexs into vertex buffer by mapping it
At EnterFrame
void InitPipeline()
{
// load and compile the two shaders
ID3D10Blob *VS,*PS;
D3DX11CompileFromFile("shaders.hlsl",0,0,"VShader","vs_4_0",0,0,0,&VS,0,0);
D3DX11CompileFromFile("shaders.hlsl",0,0,"PShader","ps_4_0",0,0,0,&PS,0,0);
// encapsulate both shaders into shader objects
dev->CreateVertexShader(VS->GetBufferPointer(),VS->GetBufferSize(),NULL,&pVS);
dev->CreatePixelShader(PS->GetBufferPointer(),PS->GetBufferSize(),NULL,&pPS);
// set the shader objects
devcon->VSSetShader(pVS,0,0);
devcon->PSSetShader(pPS,0,0);
//Create Input layout object,Created input element descriptions for the position and the color.
D3D11_INPUT_ELEMENT_DESC ied[] =
{
{"POSITION",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0},
{"COLOR",0,DXGI_FORMAT_R32G32B32A32_FLOAT,0,12,D3D11_INPUT_PER_VERTEX_DATA,0},
};
//Created an input layout object using the shader information.
dev->CreateInputLayout(ied,2,VS->GetBufferPointer(),VS->GetBufferSize(),&pLayout);
//Set the input layout object.
devcon->IASetInputLayout(pLayout);
}
Its do :
1.Loaded And Compiled with two shader
2.Create Object for each one
3.Set the two object
2.
Global
struct VERTEX{FLOAT X,Y,Z;D3DXCOLOR Color;};
ID3D11Buffer *pVBuffer;
void InitGraphics()
{
// create a triangle using the VERTEX struct
VERTEX OurVertices[] =
{
{0.0f,0.5f,0.0f,D3DXCOLOR(1.0f,0.0f,0.0f,1.0f)},
{0.45f,-0.5f,0.0f,D3DXCOLOR(0.0f,1.0f,0.0f,1.0f)},
{-0.45f,-0.5f,0.0f,D3DXCOLOR(0.0f,0.0f,1.0f,1.0f)}
};
//Created a vertex buffer object.
D3D11_BUFFER_DESC bd;
ZeroMemory(&bd,sizeof(bd));
bd.Usage = D3D11_USAGE_DYNAMIC;// access by CPU and GPU
bd.ByteWidth = sizeof(VERTEX) *3;//size is the vertex struct * 3
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;//use as vertex buffer
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;// allow CPU to write in buffer
dev->CreateBuffer(&bd,NULL,&pVBuffer);
//vertices into a buffer ,copy the vertices into the buffer
D3D11_MAPPED_SUBRESOURCE ms;
devcon->Map(pVBuffer,NULL,D3D11_MAP_WRITE_DISCARD,NULL,&ms);
memcpy(ms.pData,OurVertices,sizeof(OurVertices));
devcon->Unmap(pVBuffer,NULL);
}
It do:
1.Create three vertex with both position
2.Create vertex buffer object
3.Copied the vertexs into vertex buffer by mapping it
At EnterFrame
void RenderFrame(void)
{
............
//select which vertex buffer to display,Set which vertex buffer to use
UINT stride = sizeof(VERTEX);
UINT offset = 0;
devcon->IASetVertexBuffers(0,1,&pVBuffer,&stride,&offset);
//select which primtive type we are using
devcon->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
//draw the vertex buffer to the back buffer,Draw the triangle.
devcon->Draw(3,0);
//swtich the back buffer and front buffer
swapchain->Present(0,0);
}
void UnLoad3D()
{
swapchain->SetFullscreenState(FALSE,NULL);
pLayout->Release();
pVS->Release();
pPS->Release();
pVBuffer->Release();
swapchain -> Release();
backbuffer->Release();
dev ->Release();
devcon->Release();
}
Monday, November 28, 2011
DirextX -Begin D3D
The DirectX Begin
IDXGISwapChain: The swap chain is the series of buffers which take turns being rendered on.
ID3D11Device:This variable is a pointer to a device.
ID3D11DeviceContext:A device context is similar to a device, but it is responsible for managing the GPU and the rendering pipeline (the device mostly handles video memory).
Initialize D3D
UnLoad3D
Program Main
Window Program
1scd.Flags:Three property
1.DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH
2.DXGI_SWAP_CHAIN_FLAG_NONPREROTATED
3.DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE
2.scd.SampleDesc.Count: Max Number is 4 Min Number is 1 ,Setting Multisample anti-aliased
----------------------- Using Back Buffer with Deep Blue
1.Setting RenderTarget
2.Setting ViewPort
3.RenderFrame
In header i add
InitD3D(HWND hWnd)
Add Render Target &ViewPort
In game Logical Add
RenderFrame And done
#include windows.h
#include windowsx.h
#include d3d11.h
#include d3d10.h
#include d3d11.h
#include d3dx10.h
#include d3dx11.h
#include windows.h
#pragma comment(lib,"d3d11.lib")
#pragma comment(lib,"d3dx11.lib")
#pragma comment(lib,"d3dx10.lib")
IDXGISwapChain *swapchain;
ID3D11Device *dev;
ID3D11DeviceContext *devcon;
void InitD3D(HWND hWnd);
void CleanD3D(void);
LRESULT CALLBACK WindowProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lPram);
IDXGISwapChain: The swap chain is the series of buffers which take turns being rendered on.
ID3D11Device:This variable is a pointer to a device.
ID3D11DeviceContext:A device context is similar to a device, but it is responsible for managing the GPU and the rendering pipeline (the device mostly handles video memory).
Initialize D3D
void InitD3D(HWND hWnd)
{
DXGI_SWAP_CHAIN_DESC scd;
ZeroMemory(&scd,sizeof(DXGI_SWAP_CHAIN_DESC));
//Swap chain struct
scd.BufferCount = 1;//BackBuffer
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;//32bit-buffer
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; //how swap chain is to be used
scd.OutputWindow = hWnd;//window to be use
scd.SampleDesc.Count = 2;//How many multisample anti-aliased
scd.Windowed = TRUE;//Screen Full or not
//scd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;//use alt + enter DXGI_SWAP_CHAIN_FLAG_NONPREROTATED moniter rotation
D3D11CreateDeviceAndSwapChain(NULL,D3D_DRIVER_TYPE_HARDWARE,NULL,NULL,NULL,NULL,D3D11_SDK_VERSION,&scd,&swapchain,&dev,NULL,&devcon);
}
UnLoad3D
void Clean3D()
{
swapchain -> Release();
dev ->Release();
devcon->Release();
}
Program Main
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;
ZeroMemory(&wc,sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = "WindowClass";
RegisterClassEx(&wc);
RECT wr = {0,0,1280,720};
AdjustWindowRect(&wr,WS_OVERLAPPEDWINDOW,FALSE);
hWnd = CreateWindowEx(NULL,"WindowClass","RealDirectX",WS_OVERLAPPEDWINDOW,300,300,wr.right - wr.left,wr.bottom - wr.top,NULL,NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);
InitD3D(hWnd);
MSG msg;
while(TRUE)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if(msg.message == WM_QUIT)
break;
}
else
{
}
}
Clean3D();
return msg.wParam;
}
Window Program
LRESULT CALLBACK WindowProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}break;
}
return DefWindowProc(hWnd,message,wParam,lParam);
}
1scd.Flags:Three property
1.DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH
2.DXGI_SWAP_CHAIN_FLAG_NONPREROTATED
3.DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE
2.scd.SampleDesc.Count: Max Number is 4 Min Number is 1 ,Setting Multisample anti-aliased
----------------------- Using Back Buffer with Deep Blue
1.Setting RenderTarget
2.Setting ViewPort
3.RenderFrame
In header i add
ID3D11RenderTargetView *backbuffer;
void RenderFrame(void);
InitD3D(HWND hWnd)
Add Render Target &ViewPort
void InitD3D(HWND hWnd)
{
//........
//Setting Render Target
ID3D11Texture2D *pBackBuffer;
swapchain->GetBuffer(0,__uuidof(ID3D11Texture2D),(LPVOID*)&pBackBuffer);
dev->CreateRenderTargetView(pBackBuffer,NULL,&backbuffer);
pBackBuffer->Release();
devcon->OMSetRenderTargets(1,&backbuffer,NULL);
//Setting ViewPort
D3D11_VIEWPORT viewport;
ZeroMemory(&viewport,sizeof(D3D11_VIEWPORT));
viewport.MaxDepth = 1.0f;
viewport.MinDepth = 0.0f;
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = 1280;
viewport.Height = 720;
devcon->RSSetViewports(1,&viewport);
}
void RenderFrame(void)
{
//Clear the back buffer in deep blue
devcon->ClearRenderTargetView(backbuffer,D3DXCOLOR(0.0f,0.2f,0.4f,1.0f));
//swtich the back buffer and front buffer
swapchain->Present(0,0);
}
In game Logical Add
RenderFrame And done
Saturday, November 26, 2011
Friday, November 4, 2011
C# Interface & abstract Difference
以Tower Defend遊戲中的房屋:
Interface:
定義不同種類的物件中,針對某種特性,所需要具備的相同功能。
介面是對行為的抽象:任何類別若繼承介面並且實做後,皆具有此功能。
1.All the Mothod , property , event must be public。
2. 繼承Interface 物件,New 出一個interface 物件,Interface 內的method property 一定要被實做出來。
3.多重繼承
Abstract:
介面是對行為的抽象:任何類別若繼承介面並且實做後,皆具有此功能。
1. abstract class can be private or protected
2.you can new a abstract class but not doing anything
----------------------------------------------Edit Continue
Interface:
定義不同種類的物件中,針對某種特性,所需要具備的相同功能。
介面是對行為的抽象:任何類別若繼承介面並且實做後,皆具有此功能。
1.All the Mothod , property , event must be public。
2. 繼承Interface 物件,New 出一個interface 物件,Interface 內的method property 一定要被實做出來。
3.多重繼承
Abstract:
介面是對行為的抽象:任何類別若繼承介面並且實做後,皆具有此功能。
1. abstract class can be private or protected
2.you can new a abstract class but not doing anything
----------------------------------------------Edit Continue
Friday, October 7, 2011
Kinect SkeletonTracking-Sample
KinectNote
Project Type : window Form application
Step 1.
Initialize
------------------------------------------------------------
------------------------------------------------------------
Step 2.
Method
Project Type : window Form application
using Microsoft.Research.Kinect.Nui;
using Coding4Fun.Kinect.WinForm;
Step 1.
Initialize
------------------------------------------------------------
Runtime nui;
InLoading Event
nui = new Runtime();
nui.Initialize(RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseColor);
nui.VideoFrameReady += new EventHandler(nui_VideoFrameReady);
nui.SkeletonFrameReady +=new EventHandler (nui_SkeletonFrameReady);
//OpenStram
nui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480,
ImageType.Color);
1.ImageStreamType :Video ,Depth,Invalid.
2.int : Depend on PC performance. 1 is batter .
3.ImageResolution: Kinect Video Resolution 640x480 can keep frame 30.
4.ImageType: Color,Depth.
1.RuntimeOption:
i.UseSkeletalTracking :Tracing Player Skeleton.
ii.UseColor : Image From Kinect.
iii.UseDepthAndPlayerIndex: Give multi player index And Depth Dector.------------------------------------------------------------
Step 2.
Method
void nui_VideoFrameReady(object sender, ImageFrameReadyEventArgs e)
{
//Using Coding4Fun's DLL
//picColorVideo is PictureBox
picColorVideo.Image= e.ImageFrame.ToBitmap();
//If not using Coding4Fun's DLL
//PlanerImage data = e.ImageFrame.Image;
//picColorVideo.Source = BitmapSource.Create(data.Width,data.Height,96,96,
// PixelFormats.Bgr32,null,data.Bits,data.Width*data.BytesPerPixel);
}
// Kinect coordinate Transfer Screen coordinate
Point GetDisplayPosition(Joint joint)
{
float depthX, depthY;
nui.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
depthX = Math.Max(0,Math.Min(depthX *320,320));
depthY = Math.Max(0, Math.Min(depthY * 240, 240));
int colorX, colorY;
nui.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480,
new ImageViewArea(), (int)depthX, (int)depthY, (short)0, out colorX, out colorY);
return new Point(colorX * picColorVideo.Width / 640, colorY * picColorVideo.Height / 480);
}
void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
foreach (SkeletonData data in e.SkeletonFrame.Skeletons)
{
if (data.TrackingState == SkeletonTrackingState.Tracked)
{
JointsCollection jc = data.Joints;
StringBuilder sb = new StringBuilder();
foreach (JointID jid in Enum.GetValues(typeof(JointID)))
{
if (jid != JointID.Count)
{
Point p = GetDisplayPosition(jc[jid]);
sb.Append(string.Format("{0}={1},{2}\n", jid, p.X, p.Y));
}
}
//lblJoins is Labl
lblJoins.Text = sb.ToString();
}
}
}
------------------------------------------------------------
SkeletonTrackingState
Tracked - player have been detected.
PositionOnly- player have been cut,Kinect hard to detect.
NotTracked - The Joint doesn't be detect(It is hard to happen)
Joints TransformSmooth
nui.SkeletonEngine.TransformSmooth = true;
Advance
1.Use TransformSmoothParameters
nui.SkeletonEngine.SmoothParameters.
Correction
JitterRadius
MaxDeviation
Prediction
Smoothing
Saturday, October 1, 2011
Different about List between Add Method and Remove Method
C# List Note
http://allantech.blogspot.com/2007/03/performance-arraylist-vs-list.html
Array : array element can be of any type,including an array type , an array with n elements and
the "n" must be given a value.
List: List element can be a strongly typed list of objects that can be accessed by index.List with
elements can be any Length.
ArrayList : ArrayList element can be of any type,ArrayList with n elements can be any Length.
--------------------------------------------------------------------------------------------------
Java arrayList Note
get(int) : Effective.
add(Object obj) : Effective.
set(int index,Object obj):Effective.
add(int index,Object obj):Low Effective.
remove(int index): Low Effective.
contains(Object obj):Low Effective.(Because Of Calling index Of)
Remove List Way:
1.Use Remove method,Delete Element.
2.Rebird new ArrayList,Insert Useless Element.
--------------------------------------------------------------------------------------------------
Java Example
There is an ArrayList include Integer,We need to Delete odd number
public class Example
{
private static List exampleNew(int cnt)
{
List p = new ArrayList();
for(int i =0; i < cnt;i++)
p.Add(new Integer(i));
List o = new ArrayList(100);
for(int i = 0;i < p.Size();i++)
if(i%2==0)
o.Add(p.get(i));
return o;
}
private static List exampleRemove(int cnt)
{
List p = new List();
for(int i =0; i < cnt ; i++)
p.Add(new Integer(i));
for(int i = 0 ; i < p.Size();i++)
if(i%2 != 0 )
p.Remove(i);
return p;
}
public static void example(int total,int cnt)
{
double time01,time02;
time01 = System.currentTimeMillis();
for(int i =0; i < total / cnt; i ++)
exampleNew(cnt);
time02 = System.currentTimeMillis();
double time03 = time02-time01;
time01 = System.currentTimeMillis();
for(int i =0; i < total/cnt;i++)
exampleRemove(cnt);
time02 = System.currentTimeMillis();
double time04 = time02-time01
System.out.println("List Size : " + cnt);
System.out.println("using New List:" + time03+"ms");
System.out.println("using Remove:"+time04+"ms");
System.out.println("New ---- Remove" + time03/time04+ " :1");
}
public static void main(String[] args)
{
double time01,time02;
int total = 100*1000;
int cnt=1;
while(cnt <= total)
{
example(total,cnt);
cnt *=10;
}
}
}
--------------------------------------------------------------------------------------------------
Result:
When ArrayList is equal or bigger then 1000,the effective will have big different,
therefore, Use Add Metod is greater then Remove Method.
http://allantech.blogspot.com/2007/03/performance-arraylist-vs-list.html
Array : array element can be of any type,including an array type , an array with n elements and
the "n" must be given a value.
List: List element can be a strongly typed list of objects that can be accessed by index.List with
elements can be any Length.
ArrayList : ArrayList element can be of any type,ArrayList with n elements can be any Length.
--------------------------------------------------------------------------------------------------
Java arrayList Note
get(int) : Effective.
add(Object obj) : Effective.
set(int index,Object obj):Effective.
add(int index,Object obj):Low Effective.
remove(int index): Low Effective.
contains(Object obj):Low Effective.(Because Of Calling index Of)
Remove List Way:
1.Use Remove method,Delete Element.
2.Rebird new ArrayList,Insert Useless Element.
--------------------------------------------------------------------------------------------------
Java Example
There is an ArrayList include Integer,We need to Delete odd number
public class Example
{
private static List exampleNew(int cnt)
{
List p = new ArrayList();
for(int i =0; i < cnt;i++)
p.Add(new Integer(i));
List o = new ArrayList(100);
for(int i = 0;i < p.Size();i++)
if(i%2==0)
o.Add(p.get(i));
return o;
}
private static List exampleRemove(int cnt)
{
List p = new List();
for(int i =0; i < cnt ; i++)
p.Add(new Integer(i));
for(int i = 0 ; i < p.Size();i++)
if(i%2 != 0 )
p.Remove(i);
return p;
}
public static void example(int total,int cnt)
{
double time01,time02;
time01 = System.currentTimeMillis();
for(int i =0; i < total / cnt; i ++)
exampleNew(cnt);
time02 = System.currentTimeMillis();
double time03 = time02-time01;
time01 = System.currentTimeMillis();
for(int i =0; i < total/cnt;i++)
exampleRemove(cnt);
time02 = System.currentTimeMillis();
double time04 = time02-time01
System.out.println("List Size : " + cnt);
System.out.println("using New List:" + time03+"ms");
System.out.println("using Remove:"+time04+"ms");
System.out.println("New ---- Remove" + time03/time04+ " :1");
}
public static void main(String[] args)
{
double time01,time02;
int total = 100*1000;
int cnt=1;
while(cnt <= total)
{
example(total,cnt);
cnt *=10;
}
}
}
--------------------------------------------------------------------------------------------------
Result:
When ArrayList is equal or bigger then 1000,the effective will have big different,
therefore, Use Add Metod is greater then Remove Method.
Monday, September 19, 2011
Note Xna
Note Xna
Behave
if(player.X < target.X)
{
target.X -= speedVal
}
else if(player.X > target.X)
{
target.X += speedVal
}
speedVal= Random Speed to Chase
--------------------------------------------------------------------------------------
if(player.Y < position.Y)
{
position.Y += Math.Abs(speed.X);
}
else if(player.Y > position.Y)
{
position.Y -= Math.Abs(speed.X);
}
-----------------------------------------------------------------------------------------
Behave
Chase To Dead
if(player.X < target.X)
{
target.X -= speedVal
}
else if(player.X > target.X)
{
target.X += speedVal
}
speedVal= Random Speed to Chase
--------------------------------------------------------------------------------------
Chase Or Leaveing
if(speed.X == 0)
{
if(player.X < position.X)
{
position.X -= Math.Abs(speed.Y);
}
else if(player.X > position.X)
{
position.X += Math.Abs(speed.Y);
}
}
if(speed.Y ==0)
{
if(player.Y < Position.Y)
{
position.Y -= Math.Abs(speed.X);
}
else if(player.Y >position.Y)
{
position.Y += Math.Abs(speed.X);
}
}
--------------------------------------------------------------------------------------
Evading
if(player.X < position.X)
{
position.X += Math.Abs(speed.Y);
}
else if(player.X > position.X)
{
position.X -= Math.Abs(speed.Y);
}
{
position.Y += Math.Abs(speed.X);
}
else if(player.Y > position.Y)
{
position.Y -= Math.Abs(speed.X);
}
-----------------------------------------------------------------------------------------
Friday, July 8, 2011
Sunday, May 29, 2011
Subscribe to:
Posts (Atom)






