Wednesday, May 4, 2011

Following the Penelope tutorial Part 1

I started the Penelope tutorial a week ago. The touch input method is really unfamiliar to me. After reached page 31 of the tutorial, I stop there and starting to learn more in depth about the objects and function calls, because the tutorial manual is not down to the detail very deeply.

The first thing is about access the screen, there is an object "GUITexture" to deal with the touch input.

gui = GetComponent(GUITexture);

That is the texture image of the thumb pad, in addition, the pixelInset member variable store the location and dimension of the image on screen, that means, chaning gui.pixelInset.x and gui.pixelInset.y will alter the location of the image on the screen.

The second thing is how to access the input on screen, the Input class and its methods deal with both normal input (keyboard/mouse/joystick) as well as touch input.

For instance, the Input.touchCount return the number of touches, Input.touches return the list of touched objects during the last frame. Input.acceleration and Input.accelerationEvents deal with accelerometer I think.

By using Input.touchCount to get the number of touches, using Input.GetTouch(int x) in a loop to get the Touch objects of each touch.

Example:
var count : int = Input.touchCount;
for (var i : int = 0; i < count; i++) {
  var touch : Touch = Input.GetTouch(i);
}

Touch object is a struct which has several variables. For example

fingerId
The unique index for touch.
position
The position of the touch.
deltaPosition
The position delta since last change.
deltaTime
Amount of time passed since last change.
tapCount
Number of taps.
phase
Describes the phase of the touch.

Input.GetTouch(int x).position return the Vector2 variable;

Input.GetTouch(int x).phase return the Enumeration of TouchPhase

Began
A finger touched the screen.
Moved
A finger moved on the screen.
Stationary
A finger is touching the screen but hasn't moved.
Ended
A finger was lifted from the screen. This is the final phase of a touch.
Canceled
The system cancelled tracking for the touch, as when (for example) the user puts the device to her face or more than five touches happened simultaneously. This is the final phase of a touch.

Prepare Postgresql on CentOS in 5 steps

There are a lot of resource on setting up Postgres server, instead of refer the steps from different resource, I drop a notes for quick reference, this guide is written for Centos 5.x.

1. Install the Postgresql server using either YUM or Package Manager.


2. Before starting the server, run the command "service postgresql initdb" to initialize the database.

The database will create in the default location:

/var/lib/pgsql/data


3. Start the database server

chkconfig postgresql on  (set the server startup at boot time)
service postgresql start (start the server)


4. In order to allow connection for remote host, change the line in /var/lib/pgsql/data/pg_hba.conf as:

local all all trust
host all all 0.0.0.0/0 trust

And change the line in /var/lib/pgsql/data/postgresql.conf

listen_address = '*'


5. Now using pgadmin client to make a new connection:

Maintenance DB: Postgres
Username: Postgres