Friday, October 7, 2011

Kinect SkeletonTracking-Sample

KinectNote

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.







Monday, September 19, 2011

Note Xna

Note Xna
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);
}

if(player.Y < position.Y)
{
    position.Y += Math.Abs(speed.X);
}
else if(player.Y > position.Y)
{
    position.Y -= Math.Abs(speed.X);
}
-----------------------------------------------------------------------------------------

Sunday, May 29, 2011

nFringeSetup















1.檢查.UC編碼為ASCII
2.64Bit UDK.exe
3.Begin Script
4.DefaultEngine.ini
5.+EditPackage

Sunday, January 30, 2011

UDK-AutoTurret

follow by: http://udn.epicgames.com/Three/MasteringUnrealScriptStates.html


But there have some problem:

1.it can't rotate correctly

2.it shot wrong side

Solution:
http://forums.epicgames.com/showthread.php?t=717876&highlight=Turret&page=3

In  #28 Poster Said :


Step 1: Open the Editor and fully load the "TurretContent.upk" package, there should be 4 assets in it (at the time of this posting, the package contains: TurretAnims, TurretAnimTree, TurretMesh, and TurretMesh_Physics)

Step 2: Double-click on the "TurretMesh" asset in the TurretContent package to open the Animset Editor for the turret. As you can see, by default, the turret is pointing in the negative X direction which is clearly wrong because in Unreal, unrotated objects are supposed to point down the positive x axis. To compensate for this error in the turretmesh, inside the Animset Editor, look for the "Mesh" tab in the Properties window. Underneath the "SkeletalMesh" category, expand "RotOrigin" and set the Yaw value to 180 degrees. Your turret mesh should now point down the positive X axis like a proper Unreal asset . You can close the Animset editor now. This fixes the first problem with the provided turret.

Step 3: The second issue with the turret is that its bone pivots are all off. To compensate for this, inside the TurretContent package, double-click on the TurretAnimTree asset to open the AnimTree Editor. Once open, click on the green "SkelControlSingleBone: PivotController" box to bring up its properties on the bottom. Under the "Rotation" category, you should see an empty checkbox next to "bAddRotation"; however, you want this to be trueso put a check mark next to "bAddRotation". Secondly, by default, the BoneRotationSpace property just below the check box is set to "BCS_BoneSpace" by default, but this is no good because the bone pivots are all messed up. Therefore, we need to change this to "BCS_ActorSpace" instead to get what we want. Make sure you're setting this under the "Rotation" category, NOT the "Translation" category. You can close the AnimTree Editor now.

Step 4: Inside the generic browser, right-click on the TurrentContent package and SAVE! This is really important, otherwise you'll have to make these changes all over again when you reload the editor!

Done:
 Now, in UScript, when you apply rotations to the pivotController bone it should rotate the way you intend. In the editor, you can even place the turret upside-down or mount it on angled walls now and it should still track just fine (so long as you also remembered to apply the actor rotation like the tutorial tells you).







And It will Work Successful

Monday, January 24, 2011

UDK-platform

follow by :http://www.moug-portfolio.info/index.php?page=1-actors---moving-platform





Importance :
defaultProperties
{
bCollideActors=true
bBlockActors=true
}
And
if i want to stand on the platform




Use Sample Box Collision need to be unchecked

Add Function :
event Touch(Actor Other, PrimitiveComponent OtherComp, vector HitLocation, vector HitNormal)

And it need to create a CylinderComponent or something And Add the CollisionComponent And the Touch Function will Work

Monday, January 17, 2011

UDK-Camera

http://www.youtube.com/watch?v=YZDVOliU-3c

Just A Test
follow by:
UDN Camera Technical
Problem issue :

UDK ThirdPerson Camera And GoW Camera

1.Can't Use CamerClass in my customPlayerController :
    CustomPlayerCintroller
    DefaultProperties
    {
      CamerClass=class'MyGame.CustomGameCamera'  //Don't Work!
    }

----------------------------------------------------------------------------------------------
Only Attack xy-Plane

Friday, December 31, 2010

UDK-WeaponTest

Weapon Test
Weapon:Resoure Use From Dungeon_Defense For Test





















 Projectile Weapon Useing Static Mesh