Sunday, August 31, 2008

function call in javascript

I was studying russkey.mozdev.org source code to learn how to write Firefox extension.

Found this style of function call in javascript.


var collection = {

hello : function() {
document.write("Hello World!");
},

understand : function() {
document.write("<br/>Understand!");
},

bye : function() {
document.write("<br/>bye!");
}

};


var m = new collection.hello();
var n = new collection.understand();
var o = new collection.bye();



The output will

Hello World!
Understand!
bye!

Saturday, August 30, 2008

My Facebook application



apps.new.facebook.com/circle_of_blood/
or
apps.facebook.com/circle_of_blood/


Special thanks to Dr. Hamza for joining in this project and sponsor the hosting.

Wednesday, August 27, 2008

flash/swf height width in CodeIgniter 1.6

In libraries/Upload.php

Edit the function is_image().

add the 'application/x-shockwave-flash' in $img_mimes


$img_mimes = array(
'image/gif',
'image/jpeg',
'image/png',
'application/x-shockwave-flash',
);



It simply allow set_image_properties function to read the height & width for flash.

//now this will not call for flash
if ( ! $this->is_image())
{
return;
}

Tuesday, August 26, 2008

Which user remove my facebook application

To remove the user who remove your application from facebook automatically.

In the settings of the application,
"Can your application be added on Facebook?" set it yes.


Scroll down, you will get a Post-Remove URL input box.



Facebook will send data to the post remove url page about the user removing the application.
The post_remove.php example from my server.


<?php

//facebook lib
require_once 'fbclient/facebook.php';

//my database config
require_once 'config/config.php';

$appapikey = 'you_app_api_key';
$appsecret = 'your_app_secret_key';

$facebook = new Facebook($appapikey, $appsecret);
$user_id = $facebook->require_login();

$user = $facebook->get_loggedin_user();

if ($user != NULL && $facebook->fb_params['uninstall'] == 1)
{
//The user has removed your app
mysql_query("DELETE FROM users WHERE userid='$user_id'") or die(mysql_error());
}

?>


Reference:
Creating Your First Application Facebook wiki
Post-Remove URL Facebook wiki

Wednesday, August 13, 2008

Matrix in OpenGL


[0 4 8 12]
[1 5 9 13]
[2 6 10 14]
[3 7 11 15]

4x4 matrix in memory.

[R0 R3 R6 Tx]
[R1 R4 R7 Ty]
[R2 R5 R8 Tz]
[ 0 0 0 1]

'R' represents rotations and scaling (and shearing)
'T' translation


First, I read the matrix and print it.


float x[16];
int i;

//read the 4x4 matrix and store in x
glGetFloatv (GL_MODELVIEW_MATRIX, (float*)x);

//print the matrix
for(i=0; i<4; i++){
printf("%f\t%f\t%f\t%f", x[i], x[i+4], x[i+8], x[i+12]);
printf("\n");
}

glTranslatef(2, 0.0, 0.0);


//print the matrix after translate

glGetFloatv (GL_MODELVIEW_MATRIX, (float*)x);

printf("\n-----------------------\n");

for(i=0; i<4; i++){
printf("%f\t%f\t%f\t%f", x[i], x[i+4], x[i+8], x[i+12]);
printf("\n");
}



Run the program.

After translate our matrix changes in "Tx" -2.000000

-1.000000   0.000000   0.000000   0.000000
0.000000  -0.196116   0.980581   0.000000
0.000000   0.980581   0.196116  -10.198039
0.000000   0.000000   0.000000   1.000000
-----------------------------------------
-1.000000   0.000000   0.000000  -2.000000
0.000000  -0.196116   0.980581   0.000000
0.000000   0.980581   0.196116  -10.198039
0.000000   0.000000   0.000000   1.000000



Instead of translate if we use rotation

glRotatef(45, 0.0, 1.0, 1.0);

After rotation our matrix changes in "R"

-1.000000   0.000000   0.000000   0.000000
0.000000  -0.196116   0.980581   0.000000
0.000000   0.980581   0.196116  -10.198039
0.000000   0.000000   0.000000   1.000000
-----------------------------------------
-0.707107   0.500000  -0.500000   0.000000
-0.588348  -0.023793   0.808257   0.000000
0.392232   0.865699   0.310998  -10.198039
0.000000   0.000000   0.000000   1.000000




Reference: www.gamedev.net Forum