2009年11月26日 星期四

vb.net 、C# 網頁上applet






所以這叫做vb.net applet? OR C# applet?






有圖有真相










此開發環境為 windows XP 、VS 2008





VB版:





1. 建立 Windows Form 使用者控制項:










2.編譯的標籤,勾選..
『註冊OCM....』









3.在程式裡面,需要在一開使的地方做一些調整







是的,需要Import System...................



跟加上Guid、ComVisible



還有主要的 Class要繼承 UserControl

4.在AssemblyInfo.vb裡面





要加上














5.把您的超級程式碼擺進去吧。。。




..................................................






6.高興的按下三角形編譯吧





7.這個時候HTML需要製作了



OK,大功告成...

C#版的話,自行想像。。。基本上很相近

2009年10月30日 星期五

溫室裡的工程師

在矽X寫第一隻程式的時候,突然想起如果是有幾百萬筆資料,他們會怎麼想,如果使用者亂拉資料,DB Server不怕Crash掉嗎?根據溝通的結果。。。。他們說。。。銀行也只會調今年的資料,我反問說,萬一,櫃台小姐想調出5年前的交易紀錄,怎麼辦

PS.資料很有可能很大(如果每次都SELECT *....沒幾個人玩,DB Server記憶體要擴充到幾百G都有可能...)

他們:........

我:!!(。。。)

好吧,我自己想,在艾瑞克也是這樣解的。。。很多無解的問題也是這樣解的

2009年9月25日 星期五

3D座標轉2D座標

3D轉2D?聽起來很簡單。可是發現裡面牽涉一堆陣列的時候頭就痛
這是研究結果
Vector3 screenSpace = graphics.GraphicsDevice.Viewport.Project(
Vector3.Zero, cameraProjectionMaxtrix, cameraViewMaxtrix, new Matrix(0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.1f, 0.0f
, ship.position.X, ship.position.Y, ship.position.Z, 1.0f));

座標就在這裡出現
screenSpace.X ←怪物的X座標
screenSpace.Y ←怪物的Y座標

利用此座標,在怪物或是機械死亡的瞬間,繪出爆炸效果,就是爆破了

2009年9月22日 星期二

XNA畫線


介紹一下XNA劃線功能,vb劃線很簡單 System.DrawLine(參數自己查...)
,可是XNA卻搞一堆鬼東西,明明號稱『123,站著寫真簡單』,真是不簡單
不廢話,以下為source code 自己抄
namespace DrawLine1
{
///
/// This is the main type for your game
///

public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;


VertexPositionNormalTexture[] line; // Our start and end points.
Matrix world, projection, view; // Transformation Matrices
BasicEffect basicEffect; // Standard Effect to draw with
VertexDeclaration vertexDeclaration; // Our format for the line.
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

///
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
///

protected override void Initialize()
{
// TODO: Add your initialization logic here
InitializeTransforms();
InitializeBasicEffect();
base.Initialize();
}
private void InitializeTransforms()
{
world = Matrix.CreateTranslation(new Vector3(-1.5f, -0.5f, 0.0f));
view = Matrix.CreateLookAt(
new Vector3(0.0f, 0.0f, 7.0f),
new Vector3(0.0f, 0.0f, 0.0f),
Vector3.Up
);
projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45),
(float)graphics.GraphicsDevice.Viewport.Width /
(float)graphics.GraphicsDevice.Viewport.Height,
1.0f, 100.0f);
}
///
/// Setup up the required effect so we can see our scene
///

private void InitializeBasicEffect()
{
// Not part of the Effect per se, but is required for drawing
vertexDeclaration = new VertexDeclaration(
graphics.GraphicsDevice,
VertexPositionNormalTexture.VertexElements
);
basicEffect = new BasicEffect(graphics.GraphicsDevice, null);
basicEffect.DiffuseColor = new Vector3(1.0f, 1.0f, 1.0f);
basicEffect.World = world;
basicEffect.View = view;
basicEffect.Projection = projection;
}
///
/// LoadContent will be called once per game and is the place to load
/// all of your content.
///

protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);

// TODO: use this.Content to load your game content here
}

///
/// UnloadContent will be called once per game and is the place to unload
/// all content.
///

protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

///
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
///

/// Provides a snapshot of timing values.
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();

// TODO: Add your update logic here

base.Update(gameTime);
}
private void DrawLine()
{
line = new VertexPositionNormalTexture[2];
line[0] = new VertexPositionNormalTexture(new Vector3(0, 0, 0),
Vector3.Forward,
Vector2.One
);
line[1] = new VertexPositionNormalTexture(new Vector3(0, 1, 0),
Vector3.Forward,
Vector2.One
);
graphics.GraphicsDevice.DrawUserIndexedPrimitives(
PrimitiveType.LineList,
line,
0, // vertex buffer offset to add to each element of the index buffer
2, // number of vertices in pointList
new short[2] { 0, 1 }, // the index buffer
0, // first index element to read
1 // number of primitives to draw
);
}
///
/// This is called when the game should draw itself.
///

/// Provides a snapshot of timing values.
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
graphics.GraphicsDevice.VertexDeclaration = vertexDeclaration;
// The effect is a compiled effect created and compiled elsewhere
// in the application.
basicEffect.Begin();
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Begin();
DrawLine();
pass.End();
}
basicEffect.End();
// TODO: Add your drawing code here

base.Draw(gameTime);
}
}
}

2009年9月14日 星期一

打飛碟









目前進度:
機關槍
打到會爆炸
用滑鼠瞄準目標
滑鼠滾輪縮放
標示目前使用的武器
武器攻擊力、速度、冷卻時間設定
敵人爆炸會振動
進度棒
切換武器按鈕
未完成:
主選單
劇情
增加子砲塔


ps.為什麼我的工作不是寫遊戲。。。。

2009年9月10日 星期四

XNA小塔射飛碟(VI) 發射子彈時播放聲音



//Game1.cs
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace BG_3D
{
///
/// This is the main type for your game
///

public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

GameObject terrain = new GameObject();
GameObject missileLauncherBase = new GameObject();
GameObject missileLauncherHead = new GameObject();

const int numMissiles = 2000;
GameObject[] missiles;

GamePadState previousState;
#if !XBOX
KeyboardState previousKeyboardState;
#endif

const float launcherHeadMuzzleOffset = 20.0f;
const float missilePower = 20.0f;

AudioEngine audioEngine;
SoundBank soundBank;
WaveBank waveBank;

Vector3 cameraPosition = new Vector3(0.0f, 60.0f, 160.0f);
Vector3 cameraLookAt = new Vector3(0.0f, 50.0f, 0.0f);
Matrix cameraProjectionMatrix;
Matrix cameraViewMatrix;

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

///
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
///

protected override void Initialize()
{
// TODO: Add your initialization logic here

base.Initialize();
}

///
/// LoadContent will be called once per game and is the place to load
/// all of your content.
///

protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);

audioEngine = new AudioEngine("Content\\Audio\\TutorialAudio.xgs");
waveBank = new WaveBank(audioEngine, "Content\\Audio\\Wave Bank.xwb");
soundBank = new SoundBank(audioEngine, "Content\\Audio\\Sound Bank.xsb");

cameraViewMatrix = Matrix.CreateLookAt(
cameraPosition,
cameraLookAt,
Vector3.Up);

cameraProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45.0f),
graphics.GraphicsDevice.Viewport.AspectRatio,
1.0f,
10000.0f);

terrain.model = Content.Load(
"Models\\terrain");

missileLauncherBase.model = Content.Load(
"Models\\launcher_base");
missileLauncherBase.scale = 0.2f;

missileLauncherHead.model = Content.Load(
"Models\\launcher_head");
missileLauncherHead.scale = 0.2f;
missileLauncherHead.position = missileLauncherBase.position +
new Vector3(0.0f, 20.0f, 0.0f);

missiles = new GameObject[numMissiles];
for (int i = 0; i < numMissiles; i++)
{
missiles[i] = new GameObject();
missiles[i].model =
Content.Load("Models\\missile");
missiles[i].scale = 3.0f;
}

// TODO: use this.Content to load your game content here
}

///
/// UnloadContent will be called once per game and is the place to unload
/// all content.
///

protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

///
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
///

/// Provides a snapshot of timing values.
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();

GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);

missileLauncherHead.rotation.Y -=
gamePadState.ThumbSticks.Left.X * 0.1f;

missileLauncherHead.rotation.X +=
gamePadState.ThumbSticks.Left.Y * 0.1f;

#if !XBOX
KeyboardState keyboardState = Keyboard.GetState();
if(keyboardState.IsKeyDown(Keys.Left))
{
missileLauncherHead.rotation.Y += 0.05f;
}
if(keyboardState.IsKeyDown(Keys.Right))
{
missileLauncherHead.rotation.Y -= 0.05f;
}
if(keyboardState.IsKeyDown(Keys.Up))
{
missileLauncherHead.rotation.X += 0.05f;
}
if(keyboardState.IsKeyDown(Keys.Down))
{
missileLauncherHead.rotation.X -= 0.05f;
}
#endif

missileLauncherHead.rotation.Y = MathHelper.Clamp(
missileLauncherHead.rotation.Y,
-MathHelper.PiOver4, MathHelper.PiOver4);

missileLauncherHead.rotation.X = MathHelper.Clamp(
missileLauncherHead.rotation.X,
0, MathHelper.PiOver4);

if (gamePadState.Buttons.A == ButtonState.Pressed &&
previousState.Buttons.A == ButtonState.Released)
{
FireMissile();
}

#if !XBOX
//if(keyboardState.IsKeyDown(Keys.Space) &&
// previousKeyboardState.IsKeyUp(Keys.Space))
if(keyboardState.IsKeyDown(Keys.Space))
{
FireMissile();
}
#endif

UpdateMissiles();

audioEngine.Update();

previousState = gamePadState;
#if !XBOX
previousKeyboardState = keyboardState;
#endif

// TODO: Add your update logic here

base.Update(gameTime);
}

void FireMissile()
{
foreach (GameObject missile in missiles)
{
if (!missile.alive)
{
soundBank.PlayCue("missilelaunch");

missile.velocity = GetMissileMuzzleVelocity();
missile.position = GetMissileMuzzlePosition();
missile.rotation = missileLauncherHead.rotation;
missile.alive = true;
break;
}
}
}

Vector3 GetMissileMuzzleVelocity()
{
Matrix rotationMatrix =
Matrix.CreateFromYawPitchRoll(
missileLauncherHead.rotation.Y,
missileLauncherHead.rotation.X,
0);

return Vector3.Normalize(
Vector3.Transform(Vector3.Forward,
rotationMatrix)) * missilePower;
}

Vector3 GetMissileMuzzlePosition()
{
return missileLauncherHead.position +
(Vector3.Normalize(
GetMissileMuzzleVelocity()) *
launcherHeadMuzzleOffset);
}

void UpdateMissiles()
{
foreach (GameObject missile in missiles)
{
if (missile.alive)
{
missile.position += missile.velocity;
if (missile.position.Z < -1000.0f)
{
missile.alive = false;
}
}
}
}

///
/// This is called when the game should draw itself.
///

/// Provides a snapshot of timing values.
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

DrawGameObject(terrain);
DrawGameObject(missileLauncherBase);
DrawGameObject(missileLauncherHead);

foreach (GameObject missile in missiles)
{
if (missile.alive)
{
DrawGameObject(missile);
}
}

// TODO: Add your drawing code here

base.Draw(gameTime);
}

void DrawGameObject(GameObject gameobject)
{
foreach (ModelMesh mesh in gameobject.model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.PreferPerPixelLighting = true;

effect.World =
Matrix.CreateFromYawPitchRoll(
gameobject.rotation.Y,
gameobject.rotation.X,
gameobject.rotation.Z) *

Matrix.CreateScale(gameobject.scale) *

Matrix.CreateTranslation(gameobject.position);

effect.Projection = cameraProjectionMatrix;
effect.View = cameraViewMatrix;
}
mesh.Draw();
}
}
}
}

//GameObject.cs
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace BG_3D
{
///
/// This is the main type for your game
///

public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

GameObject terrain = new GameObject();
GameObject missileLauncherBase = new GameObject();
GameObject missileLauncherHead = new GameObject();

const int numMissiles = 2000;
GameObject[] missiles;

GamePadState previousState;
#if !XBOX
KeyboardState previousKeyboardState;
#endif

const float launcherHeadMuzzleOffset = 20.0f;
const float missilePower = 20.0f;

AudioEngine audioEngine;
SoundBank soundBank;
WaveBank waveBank;

Vector3 cameraPosition = new Vector3(0.0f, 60.0f, 160.0f);
Vector3 cameraLookAt = new Vector3(0.0f, 50.0f, 0.0f);
Matrix cameraProjectionMatrix;
Matrix cameraViewMatrix;

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

///
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
///

protected override void Initialize()
{
// TODO: Add your initialization logic here

base.Initialize();
}

///
/// LoadContent will be called once per game and is the place to load
/// all of your content.
///

protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);

audioEngine = new AudioEngine("Content\\Audio\\TutorialAudio.xgs");
waveBank = new WaveBank(audioEngine, "Content\\Audio\\Wave Bank.xwb");
soundBank = new SoundBank(audioEngine, "Content\\Audio\\Sound Bank.xsb");

cameraViewMatrix = Matrix.CreateLookAt(
cameraPosition,
cameraLookAt,
Vector3.Up);

cameraProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45.0f),
graphics.GraphicsDevice.Viewport.AspectRatio,
1.0f,
10000.0f);

terrain.model = Content.Load(
"Models\\terrain");

missileLauncherBase.model = Content.Load(
"Models\\launcher_base");
missileLauncherBase.scale = 0.2f;

missileLauncherHead.model = Content.Load(
"Models\\launcher_head");
missileLauncherHead.scale = 0.2f;
missileLauncherHead.position = missileLauncherBase.position +
new Vector3(0.0f, 20.0f, 0.0f);

missiles = new GameObject[numMissiles];
for (int i = 0; i < numMissiles; i++)
{
missiles[i] = new GameObject();
missiles[i].model =
Content.Load("Models\\missile");
missiles[i].scale = 3.0f;
}

// TODO: use this.Content to load your game content here
}

///
/// UnloadContent will be called once per game and is the place to unload
/// all content.
///

protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

///
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
///

/// Provides a snapshot of timing values.
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();

GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);

missileLauncherHead.rotation.Y -=
gamePadState.ThumbSticks.Left.X * 0.1f;

missileLauncherHead.rotation.X +=
gamePadState.ThumbSticks.Left.Y * 0.1f;

#if !XBOX
KeyboardState keyboardState = Keyboard.GetState();
if(keyboardState.IsKeyDown(Keys.Left))
{
missileLauncherHead.rotation.Y += 0.05f;
}
if(keyboardState.IsKeyDown(Keys.Right))
{
missileLauncherHead.rotation.Y -= 0.05f;
}
if(keyboardState.IsKeyDown(Keys.Up))
{
missileLauncherHead.rotation.X += 0.05f;
}
if(keyboardState.IsKeyDown(Keys.Down))
{
missileLauncherHead.rotation.X -= 0.05f;
}
#endif

missileLauncherHead.rotation.Y = MathHelper.Clamp(
missileLauncherHead.rotation.Y,
-MathHelper.PiOver4, MathHelper.PiOver4);

missileLauncherHead.rotation.X = MathHelper.Clamp(
missileLauncherHead.rotation.X,
0, MathHelper.PiOver4);

if (gamePadState.Buttons.A == ButtonState.Pressed &&
previousState.Buttons.A == ButtonState.Released)
{
FireMissile();
}

#if !XBOX
//if(keyboardState.IsKeyDown(Keys.Space) &&
// previousKeyboardState.IsKeyUp(Keys.Space))
if(keyboardState.IsKeyDown(Keys.Space))
{
FireMissile();
}
#endif

UpdateMissiles();

audioEngine.Update();

previousState = gamePadState;
#if !XBOX
previousKeyboardState = keyboardState;
#endif

// TODO: Add your update logic here

base.Update(gameTime);
}

void FireMissile()
{
foreach (GameObject missile in missiles)
{
if (!missile.alive)
{
soundBank.PlayCue("missilelaunch");

missile.velocity = GetMissileMuzzleVelocity();
missile.position = GetMissileMuzzlePosition();
missile.rotation = missileLauncherHead.rotation;
missile.alive = true;
break;
}
}
}

Vector3 GetMissileMuzzleVelocity()
{
Matrix rotationMatrix =
Matrix.CreateFromYawPitchRoll(
missileLauncherHead.rotation.Y,
missileLauncherHead.rotation.X,
0);

return Vector3.Normalize(
Vector3.Transform(Vector3.Forward,
rotationMatrix)) * missilePower;
}

Vector3 GetMissileMuzzlePosition()
{
return missileLauncherHead.position +
(Vector3.Normalize(
GetMissileMuzzleVelocity()) *
launcherHeadMuzzleOffset);
}

void UpdateMissiles()
{
foreach (GameObject missile in missiles)
{
if (missile.alive)
{
missile.position += missile.velocity;
if (missile.position.Z < -1000.0f)
{
missile.alive = false;
}
}
}
}

///
/// This is called when the game should draw itself.
///

/// Provides a snapshot of timing values.
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

DrawGameObject(terrain);
DrawGameObject(missileLauncherBase);
DrawGameObject(missileLauncherHead);

foreach (GameObject missile in missiles)
{
if (missile.alive)
{
DrawGameObject(missile);
}
}

// TODO: Add your drawing code here

base.Draw(gameTime);
}

void DrawGameObject(GameObject gameobject)
{
foreach (ModelMesh mesh in gameobject.model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.PreferPerPixelLighting = true;

effect.World =
Matrix.CreateFromYawPitchRoll(
gameobject.rotation.Y,
gameobject.rotation.X,
gameobject.rotation.Z) *

Matrix.CreateScale(gameobject.scale) *

Matrix.CreateTranslation(gameobject.position);

effect.Projection = cameraProjectionMatrix;
effect.View = cameraViewMatrix;
}
mesh.Draw();
}
}
}
}

//Program.cs
using System;

namespace BG_3D
{
static class Program
{
///
/// The main entry point for the application.
///

static void Main(string[] args)
{
using (Game1 game = new Game1())
{
game.Run();
}
}
}
}

XNA小塔射飛碟(V) 發射子彈



//Game1.cs
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace BG_3D
{
///
/// This is the main type for your game
///

public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

GameObject terrain = new GameObject();
GameObject missileLauncherBase = new GameObject();
GameObject missileLauncherHead = new GameObject();

const int numMissiles = 2000;
GameObject[] missiles;

GamePadState previousState;
#if !XBOX
KeyboardState previousKeyboardState;
#endif

const float launcherHeadMuzzleOffset = 20.0f;
const float missilePower = 20.0f;

Vector3 cameraPosition = new Vector3(0.0f, 60.0f, 160.0f);
Vector3 cameraLookAt = new Vector3(0.0f, 50.0f, 0.0f);
Matrix cameraProjectionMatrix;
Matrix cameraViewMatrix;

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

///
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
///

protected override void Initialize()
{
// TODO: Add your initialization logic here

base.Initialize();
}

///
/// LoadContent will be called once per game and is the place to load
/// all of your content.
///

protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);

cameraViewMatrix = Matrix.CreateLookAt(
cameraPosition,
cameraLookAt,
Vector3.Up);

cameraProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45.0f),
graphics.GraphicsDevice.Viewport.AspectRatio,
1.0f,
10000.0f);

terrain.model = Content.Load(
"Models\\terrain");

missileLauncherBase.model = Content.Load(
"Models\\launcher_base");
missileLauncherBase.scale = 0.2f;

missileLauncherHead.model = Content.Load(
"Models\\launcher_head");
missileLauncherHead.scale = 0.2f;
missileLauncherHead.position = missileLauncherBase.position +
new Vector3(0.0f, 20.0f, 0.0f);

missiles = new GameObject[numMissiles];
for (int i = 0; i < numMissiles; i++)
{
missiles[i] = new GameObject();
missiles[i].model =
Content.Load("Models\\missile");
missiles[i].scale = 3.0f;
}

// TODO: use this.Content to load your game content here
}

///
/// UnloadContent will be called once per game and is the place to unload
/// all content.
///

protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

///
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
///

/// Provides a snapshot of timing values.
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();

GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);

missileLauncherHead.rotation.Y -=
gamePadState.ThumbSticks.Left.X * 0.1f;

missileLauncherHead.rotation.X +=
gamePadState.ThumbSticks.Left.Y * 0.1f;

#if !XBOX
KeyboardState keyboardState = Keyboard.GetState();
if(keyboardState.IsKeyDown(Keys.Left))
{
missileLauncherHead.rotation.Y += 0.05f;
}
if(keyboardState.IsKeyDown(Keys.Right))
{
missileLauncherHead.rotation.Y -= 0.05f;
}
if(keyboardState.IsKeyDown(Keys.Up))
{
missileLauncherHead.rotation.X += 0.05f;
}
if(keyboardState.IsKeyDown(Keys.Down))
{
missileLauncherHead.rotation.X -= 0.05f;
}
#endif

missileLauncherHead.rotation.Y = MathHelper.Clamp(
missileLauncherHead.rotation.Y,
-MathHelper.PiOver4, MathHelper.PiOver4);

missileLauncherHead.rotation.X = MathHelper.Clamp(
missileLauncherHead.rotation.X,
0, MathHelper.PiOver4);

if (gamePadState.Buttons.A == ButtonState.Pressed &&
previousState.Buttons.A == ButtonState.Released)

{
FireMissile();
}

#if !XBOX
//if(keyboardState.IsKeyDown(Keys.Space) &&
// previousKeyboardState.IsKeyUp(Keys.Space))
if (keyboardState.IsKeyDown(Keys.Space))
{
FireMissile();
}
#endif

UpdateMissiles();

previousState = gamePadState;
#if !XBOX
previousKeyboardState = keyboardState;
#endif

// TODO: Add your update logic here

base.Update(gameTime);
}

void FireMissile()
{
foreach (GameObject missile in missiles)
{
if (!missile.alive)
{
missile.velocity = GetMissileMuzzleVelocity();
missile.position = GetMissileMuzzlePosition();
missile.rotation = missileLauncherHead.rotation;
missile.alive = true;
break;
}
}
}

Vector3 GetMissileMuzzleVelocity()
{
Matrix rotationMatrix =
Matrix.CreateFromYawPitchRoll(
missileLauncherHead.rotation.Y,
missileLauncherHead.rotation.X,
0);

return Vector3.Normalize(
Vector3.Transform(Vector3.Forward,
rotationMatrix)) * missilePower;
}

Vector3 GetMissileMuzzlePosition()
{
return missileLauncherHead.position +
(Vector3.Normalize(
GetMissileMuzzleVelocity()) *
launcherHeadMuzzleOffset);
}

void UpdateMissiles()
{
foreach (GameObject missile in missiles)
{
if (missile.alive)
{
missile.position += missile.velocity;
if (missile.position.Z < -1000.0f)
{
missile.alive = false;

}
}
}
}

///
/// This is called when the game should draw itself.
///

/// Provides a snapshot of timing values.
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

DrawGameObject(terrain);
DrawGameObject(missileLauncherBase);
DrawGameObject(missileLauncherHead);

foreach (GameObject missile in missiles)
{
if (missile.alive)
{
DrawGameObject(missile);
}
}

// TODO: Add your drawing code here

base.Draw(gameTime);
}

void DrawGameObject(GameObject gameobject)
{
foreach (ModelMesh mesh in gameobject.model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.PreferPerPixelLighting = true;

effect.World =
Matrix.CreateFromYawPitchRoll(
gameobject.rotation.Y,
gameobject.rotation.X,
gameobject.rotation.Z) *

Matrix.CreateScale(gameobject.scale) *

Matrix.CreateTranslation(gameobject.position);

effect.Projection = cameraProjectionMatrix;
effect.View = cameraViewMatrix;
}
mesh.Draw();
}
}
}
}

//GameObject.cs
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace BG_3D
{
class GameObject
{
public Model model = null;
public Vector3 position = Vector3.Zero;
public Vector3 rotation = Vector3.Zero;
public float scale = 1.0f;
public Vector3 velocity = Vector3.Zero;
public bool alive = false;
}
}

//Program.cs
using System;

namespace BG_3D
{
static class Program
{
///
/// The main entry point for the application.
///

static void Main(string[] args)
{
using (Game1 game = new Game1())
{
game.Run();
}
}
}
}

XNA小塔射飛碟(IV) 把砲塔的頭加上去



//Game1.cs檔案
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace BG_3D
{
///
/// This is the main type for your game
///

public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

GameObject terrain = new GameObject();
GameObject missileLauncherBase = new GameObject();
GameObject missileLauncherHead = new GameObject();

Vector3 cameraPosition = new Vector3(0.0f, 60.0f, 160.0f);
Vector3 cameraLookAt = new Vector3(0.0f, 50.0f, 0.0f);
Matrix cameraProjectionMatrix;
Matrix cameraViewMatrix;

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

///
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
///

protected override void Initialize()
{
// TODO: Add your initialization logic here

base.Initialize();
}

///
/// LoadContent will be called once per game and is the place to load
/// all of your content.
///

protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);

cameraViewMatrix = Matrix.CreateLookAt(
cameraPosition,
cameraLookAt,
Vector3.Up);

cameraProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45.0f),
graphics.GraphicsDevice.Viewport.AspectRatio,
1.0f,
10000.0f);

terrain.model = Content.Load(
"Models\\terrain");

missileLauncherBase.model = Content.Load(
"Models\\launcher_base");
missileLauncherBase.scale = 0.2f;

missileLauncherHead.model = Content.Load(
"Models\\launcher_head");
missileLauncherHead.scale = 0.2f;
missileLauncherHead.position =
missileLauncherBase.position +
new Vector3(0.0f, 20.0f, 0.0f);

// TODO: use this.Content to load your game content here
}

///
/// UnloadContent will be called once per game and is the place to unload
/// all content.
///

protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

///
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
///

/// Provides a snapshot of timing values.
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();

GamePadState gamePadState = GamePad.GetState(
PlayerIndex.One);

missileLauncherHead.rotation.Y -=
gamePadState.ThumbSticks.Left.X * 0.1f;

missileLauncherHead.rotation.X +=
gamePadState.ThumbSticks.Left.Y * 0.1f;

#if !XBOX
KeyboardState keyboardState = Keyboard.GetState();

if(keyboardState.IsKeyDown(Keys.Left))
{
missileLauncherHead.rotation.Y += 0.05f;
}
if(keyboardState.IsKeyDown(Keys.Right))
{
missileLauncherHead.rotation.Y -= 0.05f;
}
if(keyboardState.IsKeyDown(Keys.Up))
{
missileLauncherHead.rotation.X += 0.05f;
}
if(keyboardState.IsKeyDown(Keys.Down))
{
missileLauncherHead.rotation.X -= 0.05f;
}
#endif

missileLauncherHead.rotation.Y = MathHelper.Clamp(
missileLauncherHead.rotation.Y,
-MathHelper.PiOver4, MathHelper.PiOver4);

missileLauncherHead.rotation.X = MathHelper.Clamp(
missileLauncherHead.rotation.X,
0, MathHelper.PiOver4);

// TODO: Add your update logic here

base.Update(gameTime);
}

///
/// This is called when the game should draw itself.
///

/// Provides a snapshot of timing values.
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

DrawGameObject(terrain);
DrawGameObject(missileLauncherBase);
DrawGameObject(missileLauncherHead);

// TODO: Add your drawing code here

base.Draw(gameTime);
}

void DrawGameObject(GameObject gameobject)
{
foreach (ModelMesh mesh in gameobject.model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.PreferPerPixelLighting = true;

effect.World =
Matrix.CreateFromYawPitchRoll(
gameobject.rotation.Y,
gameobject.rotation.X,
gameobject.rotation.Z) *

Matrix.CreateScale(gameobject.scale) *

Matrix.CreateTranslation(gameobject.position);

effect.Projection = cameraProjectionMatrix;
effect.View = cameraViewMatrix;
}
mesh.Draw();
}
}
}
}

//GameObject.cs
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace BG_3D
{
class GameObject
{
public Model model = null;
public Vector3 position = Vector3.Zero;
public Vector3 rotation = Vector3.Zero;
public float scale = 1.0f;
}
}

//Program.cs
using System;

namespace BG_3D
{
static class Program
{
///
/// The main entry point for the application.
///

static void Main(string[] args)
{
using (Game1 game = new Game1())
{
game.Run();
}
}
}
}

XNA小塔射飛碟(III) 建立砲塔塔底



//Game1.cs 檔案
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace BG_3D
{
///
/// This is the main type for your game
///

public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

GameObject terrain = new GameObject();
GameObject missileLauncherBase = new GameObject();

Vector3 cameraPosition = new Vector3(0.0f, 60.0f, 160.0f);
Vector3 cameraLookAt = new Vector3(0.0f, 50.0f, 0.0f);
Matrix cameraProjectionMatrix;
Matrix cameraViewMatrix;

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

///
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
///

protected override void Initialize()
{
// TODO: Add your initialization logic here

base.Initialize();
}

///
/// LoadContent will be called once per game and is the place to load
/// all of your content.
///

protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);

cameraViewMatrix = Matrix.CreateLookAt(
cameraPosition,
cameraLookAt,
Vector3.Up);

cameraProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45.0f),
graphics.GraphicsDevice.Viewport.AspectRatio,
1.0f,
10000.0f);

terrain.model = Content.Load(
"Models\\terrain");

missileLauncherBase.model = Content.Load(
"Models\\launcher_base");
missileLauncherBase.scale = 0.2f;

// TODO: use this.Content to load your game content here
}

///
/// UnloadContent will be called once per game and is the place to unload
/// all content.
///

protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

///
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
///

/// Provides a snapshot of timing values.
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();

// TODO: Add your update logic here

base.Update(gameTime);
}

///
/// This is called when the game should draw itself.
///

/// Provides a snapshot of timing values.
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

DrawGameObject(terrain);
DrawGameObject(missileLauncherBase);

// TODO: Add your drawing code here

base.Draw(gameTime);
}

void DrawGameObject(GameObject gameobject)
{
foreach (ModelMesh mesh in gameobject.model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.PreferPerPixelLighting = true;

effect.World =
Matrix.CreateFromYawPitchRoll(
gameobject.rotation.Y,
gameobject.rotation.X,
gameobject.rotation.Z) *

Matrix.CreateScale(gameobject.scale) *

Matrix.CreateTranslation(gameobject.position);

effect.Projection = cameraProjectionMatrix;
effect.View = cameraViewMatrix;
}
mesh.Draw();
}
}
}
}

//GameObject.cs檔案
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace BG_3D
{
class GameObject
{
public Model model = null;
public Vector3 position = Vector3.Zero;
public Vector3 rotation = Vector3.Zero;
public float scale = 1.0f;
}
}
//Program.cs檔案
using System;

namespace BG_3D
{
static class Program
{
///
/// The main entry point for the application.
///

static void Main(string[] args)
{
using (Game1 game = new Game1())
{
game.Run();
}
}
}
}

XNA小塔射飛碟(II) 建立背景


//Game1.cs檔案

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace BG_3D
{
///
/// This is the main type for your game
///

public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

Model terrainModel;
Vector3 terrainPosition = Vector3.Zero;

Vector3 cameraPosition = new Vector3(0.0f, 40.0f, 160.0f);
Vector3 cameraLookAt = new Vector3(0.0f, 8.0f, 0.0f);
Matrix cameraProjectionMatrix;
Matrix cameraViewMatrix;

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

///
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
///

protected override void Initialize()
{
// TODO: Add your initialization logic here

base.Initialize();
}

///
/// LoadContent will be called once per game and is the place to load
/// all of your content.
///

protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);

cameraViewMatrix = Matrix.CreateLookAt(
cameraPosition,
cameraLookAt,
Vector3.Up);

cameraProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45.0f),
graphics.GraphicsDevice.Viewport.AspectRatio,
1.0f,
10000.0f);

terrainModel = Content.Load("Models\\terrain");

// TODO: use this.Content to load your game content here
}

///
/// UnloadContent will be called once per game and is the place to unload
/// all content.
///

protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

///
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
///

/// Provides a snapshot of timing values.
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();

// TODO: Add your update logic here

base.Update(gameTime);
}

///
/// This is called when the game should draw itself.
///

/// Provides a snapshot of timing values.
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

DrawModel(terrainModel, terrainPosition);

// TODO: Add your drawing code here

base.Draw(gameTime);
}

void DrawModel(Model model, Vector3 modelPosition)
{
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.PreferPerPixelLighting = true;

effect.World = Matrix.CreateTranslation(modelPosition);
effect.Projection = cameraProjectionMatrix;
effect.View = cameraViewMatrix;
}
mesh.Draw();
}
}
}
}
//Program.cs檔案
namespace BG_3D
{
static class Program
{
///
/// The main entry point for the application.
///

static void Main(string[] args)
{
using (Game1 game = new Game1())
{
game.Run();
}
}
}
}

2009年9月9日 星期三

XNA小塔射飛碟(I) 建立程式


//Game1.cs檔案
namespace BG_3D
{
///
/// This is the main type for your game
///

public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;


public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

///
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
///

protected override void Initialize()
{
// TODO: Add your initialization logic here

base.Initialize();
}

///
/// LoadContent will be called once per game and is the place to load
/// all of your content.
///

protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);

// TODO: use this.Content to load your game content here
}

///
/// UnloadContent will be called once per game and is the place to unload
/// all content.
///

protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

///
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
///

/// Provides a snapshot of timing values.
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();

// TODO: Add your update logic here

base.Update(gameTime);
}

///
/// This is called when the game should draw itself.
///

/// Provides a snapshot of timing values.
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

// TODO: Add your drawing code here

base.Draw(gameTime);
}


}
}

//Program.cs檔案
namespace BG_3D
{
static class Program
{
///
/// The main entry point for the application.
///

static void Main(string[] args)
{
using (Game1 game = new Game1())
{
game.Run();
}
}
}
}

2009年9月4日 星期五

vb.net 表單的focus狀態

Protected Overloads Overrides Sub WndProc(ByRef m As Message)

if m.Msg= 6 //表單狀態
if m.WParam.ToInt32() = 1//表單建立

end if
if m.WParam.ToInt32() = 2//表單從後面移到前面

end if
if m.WParam.ToInt32() = 2097152//表單縮到最小
end if
if m.WParam.ToInt32() = 0 //表單從前面移到後面
end if
end if
MyBase.WndProc(m)
End Sub

2009年8月25日 星期二

基本遊戲功能

1.怎麼開窗
//Create text Window
m_Stats.Create(&m_Graphics,&m_Font);
m_Stats.Move(508,400,128,48);
m_Stats.Create(&m_Graphics,&m_Font);
m_Stats.Move(4,4,632,328);
2.怎麼換武器
//give an axe
m_CharController.Equip(m_CharController.GetCharacter(1),8,WEAPON,true);
6.目標三角形
//Create target vertex buffer
typedef struct{
float x,y,z;
D3DCOLOR Diffuse;
}sVertex;
sVertex Vert[6]={
{-20.0f , 40.0f , 0.0f , 0xFFFF4444},
{ 20.0f , 40.0f , 0.0f , 0xFFFF4444},
{ 0.0f , 20.0f , 0.0f , 0xFFFF4444},
{ 0.0f ,-20.0f , 0.0f , 0xFFFF4444},
{ 20.0f ,-40.0f , 0.0f , 0xFFFF4444},
{-20.0f ,-40.0f , 0.0f , 0xFFFF4444}
}

7.製造遊戲Button
//load button graphics
m_Buttons.Load(&m_Graphics,"..\\Data\\Buttons.bmp");
//load the terrain Mesh and set object
m_TerrainMesh.Load(&m_Graphics,"..\\Data\\Battle.x","..\\Data\\");
m_TerrainObject.Create(&m_Graphics,&m_TerrainMesh);

2009年8月14日 星期五

PDA comport 常見資訊

COM1 serial
COM2 virtual com
COM3 指定給其他GPS導航程式
COM4 IrDA
COM5 實體GPS
COM9 TMC

2009年8月5日 星期三

vb.net WebService 取得IP

_
Public Function GetIP() As String
Dim ClientIP As String
ClientIP = HttpContext.Current.Request.UserHostAddress 'Request.UserHostAddress
Return ClientIP
End Function

2009年6月29日 星期一

windows 7 試用版序號

32位的五個key:
4HJRK-X6Q28-HWRFY-WDYHJ-K8HDH
QXV7B-K78W2-QGPR6-9FWH9-KGMM7
TQ32R-WFBDM-GFHD2-QGVMH-3P9GC
6JKV2-QPB8H-RQ893-FW7TM-PBJ73
GG4MQ-MGK72-HVXFW-KHCRF-KW6KY

64位的五個key:
JYDV8-H8VXG-74RPT-6BJPB-X42V4
D9RHV-JG8XC-C77H2-3YF6D-RYRJ9
482XP-6J9WR-4JXT3-VBPP6-FQF4M
RFFTV-J6K7W-MHBQJ-XYMMJ-Q8DCH
7XRCQ-RPY28-YY9P8-R6HD8-84GH3

2009年6月25日 星期四

(轉載) CMD命令速查

ASSOC
顯示或修改檔案附檔名關聯。
AT
排定電腦上要執行的命令和程式。
ATTRIB
顯示或變更檔案屬性。
BREAK
設定或清除擴充的CTRL+C檢查。
CACLS
顯示或修改檔案的存取控制清單(ACLs)。
CALL
從另一個批次程式呼叫一個批次程式。
CD
顯示目前目錄的名稱或變更。
CHCP
顯示或設定作用中的字碼編號。
CHDIR
顯示目前目錄的名稱或變更。
CHKDSK
檢查磁碟並顯示狀態報告。
CHKNTFS
顯示或修改開機時的磁碟檢查。
CLS
清除螢幕。
CMD
開始新的Windows命令轉譯器。
COLOR
設定預設主控台的前景和背景色彩。
COMP
比較兩個或兩組檔案的內容。
COMPACT
顯示或變更NTFS磁碟分割上的檔案壓縮。
CONVERT
將FAT磁碟區轉換成NTFS格式。您不可轉換目前的磁碟機。
COPY
將一個或數個檔案複製到另一個位置。
DATE
顯示或設定日期。
DEL
刪除檔案。
DIR
顯示目錄中的檔案和子目錄清單。
DISKCOMP
比較兩張磁片的內容。
DISKCOPY
將磁片上的內容複製到另一張磁片上。
DOSKEY
編輯命令列、恢復Windows命令和建立巨集。
ECHO
顯示訊息、開啟或關閉命令回音。
ENDLOCAL
結束批次檔環境變更的本土化工作。
ERASE
刪除一個或更多檔案。
EXIT
結束CMD.EXE程式(命令轉譯器)。
FC
比較兩個或兩組檔案,然後顯示兩者之間的相異處。
FIND
在檔案中搜尋文字字串。
FINDSTR
在檔案中搜尋字串。
FOR
在一組檔案中的每個檔案執行一個特定的命令。
FORMAT
將磁碟格式化供Windows使用。
FTYPE
顯示或修改用於檔案附檔名關聯中的檔案類型。
GOTO
將Windows命令轉譯器指向批次程式中已經加了標籤的列。
GRAFTABL
啟用Windows在圖形模式下顯示擴充的字集。
HELP
為Windows命令提供說明資訊。
IF
在批次程式中執行有條件的處理程序。
LABEL
建立、變更或刪除磁碟的磁碟區標籤。
MD
建立目錄。
MKDIR
建立目錄。
MODE
設定系統裝置。
MORE
一次顯示一個螢幕的輸出。
MOVE
從一個目錄移動一個或數個檔案到另一個目錄。
PATH
顯示或設定執行檔的搜尋路徑。
PAUSE
暫停處理批次檔並顯示訊息。
POPD
還原PUSHD儲存的目錄之前的值。
PRINT
列印文字檔案。
PROMPT
變更Windows的命令提示。
PUSHD
儲存目前的目錄,然後變更它。
RD
移除目錄。
RECOVER
從損壞或不良的磁碟中修復可讀取的資訊。
REM
在批次檔或CONFIG.SYS鐘記錄意見(註解)。
REN
重新命名檔案。
RENAME
重新命名檔案。
REPLACE
取代檔案。
RMDIR
移除目錄。
SET
顯示、設定或移除Windows環境變數。
SETLOCAL
開始批次檔中環境變更的本土化工作。
SHIFT
變更批次檔中可取代參數的位置。
SORT
將輸入排序。
START
開始另一個視窗來執行指定的程式或命令。
SUBST
將路徑與磁碟機代號相關聯。
TIME
顯示或設定系統時間。
TITLE
設定CMD.EXE工作階段的視窗標題。
TREE
以圖形顯示磁碟機或路徑的目錄結構。
TYPE
顯示文字檔的內容。
VER
顯示Windows版本。
VERIFY
告訴Windows是否要檢查您的檔案寫入磁片時正確與否。
VOL
顯示磁碟區標籤和序號。
XCOPY
複製檔案和樹狀目錄。

2009年6月14日 星期日

vb.net Application.AddMessageFilter

Visual Basic複製程式碼
' Creates a message filter.
_
Public Class TestMessageFilter
Implements IMessageFilter

_
Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) _
As Boolean Implements IMessageFilter.PreFilterMessage
' Blocks all the messages relating to the left mouse button.
If ((m.Msg >= 513) And (m.Msg <= 515)) Then
Console.WriteLine("Processing the messages : " & m.Msg)
Return True
End If
Return False
End Function
End Class

2009年6月3日 星期三

轉載--Java2 SDK安裝對註冊表的修改

Java2 SDK安裝對註冊表的修改
Written by anson 2002-8-23

將會生成如下3個項目:



HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Plug-in
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment

同時,Java2 SDK安裝程序將會把java.exe,javaw.exe,javareg.exe這3個可執行文件拷貝到winnt\system32目錄下,由於 winnt\system32被操作系統缺省的設置為最高優先權的PATH搜索路徑,因此可保證用戶在命令行任何目錄下可運行java.exe來啟動 JVM。

那麼java.exe在啟動時如何確定其JRE所在的目錄以及需要動態加載的鏈接庫呢?java.exe是通過下面方式來確定的:

假如存在../jre/bin/java.dll文件,則查找../jre/lib/ jvm.cfg文件,在該文件中,第1個被列出的jvm.dll類型作為缺省值(假如在java.exe命令行指定了jvm.dll的類型,則使用指定類型)。jvm.dll類型分為hotspot,classic,server三種。假如不存在../jre/lib/jvm.cfg文件,則打印下面的錯誤信息:

Error: could not open 'c:\jdk1.3\jre\lib\jvm.cfg'

如不存在../jre/bin/java.dll(當運行的是winnt\system32\java.exe),則註冊表將在此時發揮作用, HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\ CurrentVersion鍵值所記錄的實際上是winnt\system32\java.exe的版本值,該版本值只保存主、次兩個版本號,如 1.2,1.3等。

同時java.exe程序內部本身也有一個標識自身的版本值,如1.2、1.3等。java.exe根據自己內部的版本值和 CurrentVersion值相比較,如果發現兩個值相等,則將在HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\ Java Runtime Environment\MainVersion.MicroVersion項下獲取JRE所在目錄及動態鏈接庫,這兩個鍵的名稱分別是JavaHome 和RuntimeLib,MainVersion表示主版本號,MicroVersion表示次版本號。

如果java.exe內部版本值和CurrentVersion不一致,則報類似以下的錯誤:

Registry key 'Software\JavaSoft\Java Runtime Environment\CurrentVersion'
has value '1.2', but '1.3' is required.

意思是說,註冊表當前所記載的winnt\system32\java.exe版本為1.2,但是此時運行的java.exe版本為1.3。java.exe抱怨除非註冊表有1.3版的記載,否則自己無法正確定位JRE目錄和jvm.dll,因此提示1.3是需要的。

這裡,我們不能簡單的修改註冊表的CurrentVersion值來達到這個目的。一般地,當在系統中裝了兩套版本的Java2 SDK(如先裝1.2而後又裝了1.3),後面安裝的Java2 SDK會將自己帶的java.exe和javaw.exe拷貝到winnt\system32目錄下,從而覆蓋先前版本的java.exe和 javaw.exe,並且在註冊表中改寫CurrentVersion為1.3。所以建議在安裝Java2 SDK前,先卸載以前安裝的版本。如果人為的修改CurrentVersion,會使得不同版本的java.exe加載與己版本不符的java.dll及 jvm.dll,將引起難以預料的後果!

特殊情況:

JBuilder自己帶一套JDK,在JBuilder安裝完成後,JBuilder安裝程序會修改CurrentVersion為自己所帶JDK的版本,但不會覆蓋winnt\system32下的java.exe和javaw.exe。

WebLogic自己帶一套JDK,在WebLogic安裝完成後,WebLogic安裝程序不會修改註冊表,也不會覆蓋winnt\system32下的java.exe和javaw.exe。

Oracle自己帶一套JDK(一般是比較低版本的,例如8.1.7僅僅帶JDK 1.1.7),在Oracle安裝完成後,Oracle安裝程序不會修改註冊表,也不會覆蓋winnt\system32下的java.exe和 javaw.exe。但是,Oralce安裝程序會修改系統PATH變量,將自帶的JRE的bin路徑加入其中,且置於最前面。隨著Oracle安裝版本的不同,其自帶JRE的JVM啟動程序也不同。在筆者機器上安裝的Oracle 8.1.7,其JRE就裝在C:\Program Files\Oracle下,並將C:\Program Files\Oracle\jre\1.1.7\bin放在PATH變量最前,其JVM啟動程序是jre.exe而非java.exe。

以上就是Java2 SDK在Windows下安裝時所做的動作,這樣會帶來兼容性問題:

問題背景:安裝Java2 SDK後,安裝了JBuilder6,未修改任何PATH變量

問題1

當在操作系統中安裝了JDK 1.2,其後安裝了JBuilder6(自帶JDK 1.3.1),這時CurrentVersion為1.3,在命令行執行java -version時,提示:

Registry key 'Software\JavaSoft\Java Runtime Environment\CurrentVersion'
has value '1.3', but '1.2' is required.

解決方法:將JDK 1.2中java.exe所在路徑加入到操作系統PATH的首位,從而保證在命令行調用java時總是執行JDK 1.2中的java.exe,以使得java.exe可正確定位JRE和jvm.dll。

問題2

當在操作系統中安裝了JDK 1.3.0,而後安裝了JBuilder6(自帶JDK 1.3.1),這時CurrentVersion為1.3,但是此1.3是指向的是JBuilder6自帶的JDK 1.3.1的JRE,而非指向先前JDK 1.3.0的JRE,當在命令行執行java -version時,此時執行的是JDK 1.3.0拷貝到winnt\system32的一個java.exe副本,但打印的版本信息卻是:

java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

導致該問題的原因是java.exe只維護小數點後1位的版本號,而非2位。

解決方法:同問題1

問題3:

如果在操作系統中先安裝了JDK 1.3.0,而後安裝了帶有與安裝JDK主次版本相同的JBuilder6(帶JDK 1.3.1,前兩位相同),則問題1實際上被隱蔽了,沒有發生的機會;而問題2的隱蔽性也很強,不容易發覺,因為人們往往會忽略JDK的第3個版本號。

如問題2所敘,在命令行執行java,雖然是使用JDK 1.3.0的一個java.exe副本(winnt\system32目錄下),而實際上卻是使用JBuilder6下JDK 1.3.1的JRE及其目錄結構,其結果是當我們使用Java2的extension mechanism將jar文件放到JDK 1.3.0的jre\lib\ext目錄下時,發現達不到希望的效果 – 在命令行用java啟動程序時,不會自動去JDK 1.3.0的jre\lib\ext目錄下去搜索jar文件,它只會去JBuilder6下JDK 1.3.1的jre\lib\ext去搜索jar文件,而JBuilder6下的JDK 1.3.1並不存在jre\lib\ext這麼一個目錄!

問題3極為隱蔽,除非完全對Java2 SDK的安裝及class定位機制瞭解,一般的開發者是難以發現問題所在的。有關Java2中class定位機制,見《Java2中的class定位機制》一文。

事實上,即使僅僅在系統中存在一份JDK 1.3.0,如果在命令行運行java的話,使用的JRE目錄是C:\Program Files\JavaSoft\JRE\1.3,也就是說,即使我們在c:\jdk1.3\jre\lib\ext下放置我們的extension jar,也得不到預期的結果。正確的做法是放在C:\Program Files\JavaSoft\JRE\1.3\lib\ext目錄下。

解決方法:同問題1

綜上所敘,強烈建議將%JDK_HOME%\bin目錄放在Windows操作系統的PATH變量的首位,以避免潛在的問題。

而在UNIX下,則完全不存在類似Windows操作系統上的問題。

我們在命令下執行的java是/bin/java

$which java
$/bin/java

而/bin是到/usr/bin的鏈接,也就是說/bin/java實際上是/usr/bin/java

而/usr/bin/java實際上鏈接到/usr/java/bin/java,/usr/java是到/usr/java1.2的鏈接(Solaris 7或更高系統內置JDK 1.2),所以我們實際上執行的java是

/usr/java1.2/bin/java

根據UNIX上的情況,java在運行時實際上總是可以用../jre/lib/sparc/libjava.so和.. /jre/lib/sparc/libjvm.so來找到這2個文件,前者類似於Windows下的java.dll,而後者類似於Windows下的 jvm.dll。所以java也總是可以確定自己JRE的目錄。

Windows和UNIX上用到的動態鏈接庫,實際上在Sun的文檔中稱為optional package's native code binaries,optional pakage實際上即為extension mechanism classes,詳見《Java2中的class定位機制》。

要更改UNIX上java的版本,更改/usr/java的鏈接是其中一個方法,具體可參見JDK在UNIX上的安裝介紹。

補充:(2002-12-23)

Windows如何定位Plug-in

根據在PATH環境變量中找到的java.exe的版本號,到HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\ Java Plug-in下尋找對應版本的Java Plug-in,在HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Plug-in下可以有多個版本的Plug-in存在。

不依賴HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit的CurrentVersion值和HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment的CurrentVersion值來定位應該使用哪個版本的Java Plug-in。

2009年5月27日 星期三

vb.net 自動撥 ADSL (pppoe)

1.先設定好ADSL連線項目,名稱取名為 adsl


2. 在vb.net 裡面寫一段程式碼
Public Function Cmd(ByVal Command As String) As String
Dim process As New System.Diagnostics.Process()
process.StartInfo.FileName = "cmd.exe"
process.StartInfo.UseShellExecute = False
process.StartInfo.RedirectStandardInput = True
process.StartInfo.RedirectStandardOutput = True
process.StartInfo.RedirectStandardError = True
process.StartInfo.CreateNoWindow = True
process.Start()
process.StandardInput.WriteLine(Command)
process.StandardInput.WriteLine("exit")
Dim Result As String = process.StandardOutput.ReadToEnd()
process.Close()
Return Result
End Function

3.關鍵為 rasphone.exe
'自己去撥號
Cmd("rasphone.exe -d adsl")

至於怎麼偵測網路斷線就是自己的本領了,可以去ping中華電信的DNS,看看是不是活著,或者....
自己發揮

2009年4月13日 星期一

informix 匯出資料庫

dbschema -d yohomis -t rfid_card_m -ss rfid_card_m.sql2
匯出yohomis 裡的 rfid_card_m 到 rfid_card_m.sql2文字檔內
vi rfid_card_m.sql2
編輯 rfid_card_m.sql2 文字檔
dd 刪行
u 回復
yy 複製
p 貼上
x 刪字

2009年4月9日 星期四

vb.net 輸入pn300 ( ScanCode )

'API 宣告
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Integer

Dim SCode As Integer
V_caps_lock_stats = My.Computer.Keyboard.CapsLock '是否按下caps lock
For Ii = 1 To V_data1.Length
tmp_str = Mid(V_data1, Ii, 1) '第幾個字
SCode = MapVirtualKey(Asc(tmp_str), 0) '找出scane code
If V_caps_lock_stats = False Then
keybd_event(&H14, 0, &H0, 0) 'caps lockey down
keybd_event(&H14, 0, &H2, 0)
End If
keybd_event(Asc(tmp_str), SCode, 0, 0) '送出字串以及scan code
keybd_event(Asc(tmp_str), SCode, 2, 0) '
If V_caps_lock_stats = False Then '
keybd_event(&H14, 0, &H0, 0) 'caps lockey down
keybd_event(&H14, 0, &H2, 0) '
End If
Next
'For Ii = 1 To 200
' Threading.Thread.Sleep(1)
' Application.DoEvents()
'Next
keybd_event(13, MapVirtualKey(13, 0), &H0, 0) 'enter lockey down
keybd_event(13, MapVirtualKey(13, 0), &H2, 0)

2009年4月6日 星期一

vb.net 播放音樂

Public Class Form1

' 宣告 API
Private Declare Function mciSendStringA Lib "winmm.dll" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer

Private Sub Button1_Click(ByVal s As Object, ByVal e As EventArgs) Handles Button1.Click
PlayMidiFile("C:\死了都要愛.mp3") ' 播放 MP3 音樂
'或
'PlayMidiFile("C:\頑皮豹.mid") ' 播放 MIDI 音樂
End Sub

Private Sub Button2_Click(ByVal s As Object, ByVal e As EventArgs) Handles Button2.Click
StopMidi() ' 停止播放
End Sub

Private Sub Button3_Click(ByVal s As Object, ByVal e As EventArgs) Handles Button3.Click
PauseMidi() ' 暫停播放
End Sub

Private Sub Button4_Click(ByVal s As Object, ByVal e As EventArgs) Handles Button4.Click
ContinueMidi() ' 繼續播放
End Sub

Private Function PlayMidiFile(ByVal MusicFile As String) As Boolean
If System.IO.File.Exists(MusicFile) Then
mciSendStringA("stop music", "", 0, 0)
mciSendStringA("close music", "", 0, 0)
mciSendStringA("open " & MusicFile & " alias music", "", 0, 0)
PlayMidiFile = mciSendStringA("play music", "", 0, 0) = 0
End If
End Function

Private Function StopMidi() As Boolean
StopMidi = mciSendStringA("stop music", "", 0, 0) = 0
mciSendStringA("close music", "", 0, 0)
End Function

Private Function PauseMidi() As Boolean
Return mciSendStringA("pause music", "", 0, 0) = 0
End Function

Private Function ContinueMidi() As Boolean
Return mciSendStringA("play music", "", 0, 0) = 0
End Function

End Class

2009年3月6日 星期五

在GAC 裡加入 ActiproSoftware.Wizard.dll(2.80.0.0)

在CMD 下
CD C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
gacutil /i ActiproSoftware.Wizard.dll