Wednesday, June 02, 2010

OpenGL: Stereoscopic rendering

Source: http://www.orthostereo.com/geometryopengl.html

Example:

GLvoid display(GLvoid)
{
glDrawBuffer(GL_BACK); //draw into both back buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear color and depth buffers

glDrawBuffer(GL_BACK_LEFT); //draw into back left buffer
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); //reset modelview matrix
gluLookAt(-IOD/2, //set camera position x=-IOD/2
0.0, // y=0.0
0.0, // z=0.0
0.0, //set camera "look at" x=0.0
0.0, // y=0.0
screenZ, // z=screenplane
0.0, //set camera up vector x=0.0
1.0, // y=1.0
0.0); // z=0.0

glPushMatrix();
{
glTranslatef(0.0, 0.0, depthZ); //translate to screenplane
drawscene();
}
glPopMatrix();

glDrawBuffer(GL_BACK_RIGHT); //draw into back right buffer
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); //reset modelview matrix
gluLookAt(IOD/2, 0.0, 0.0, 0.0, 0.0, screenZ, //as for left buffer with camera position at:
0.0, 1.0, 0.0); // (IOD/2, 0.0, 0.0)

glPushMatrix();
{
glTranslatef(0.0, 0.0, depthZ); //translate to screenplane
drawscene();
}
glPopMatrix();

glutSwapBuffers();
}

XNA: higher refresh rate

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
this.TargetElapsedTime = TimeSpan.FromMilliseconds(8);
this.IsFixedTimeStep = false;
graphics.SynchronizeWithVerticalRetrace = false;

this.IsMouseVisible = true;

}

XNA: 3D and 2D

Gotta reset settings when mixing 3D and 2D content

http://forums.xna.com/forums/t/48583.aspx

eg.:

// to reset settings for 3D drawing
graphics.GraphicsDevice.RenderState.DepthBufferEnable = true;
graphics.GraphicsDevice.RenderState.AlphaBlendEnable = false;
graphics.GraphicsDevice.RenderState.AlphaTestEnable = false;

DrawModel(gameShip);

spriteBatch.Begin();

// Draw Hello World
string output = "FPS: " + fps;

// Find the center of the string
//Vector2 FontOrigin = Font1.MeasureString(output) / 2;
Vector2 FontOrigin = FontPos;
// Draw the string
//spriteBatch.DrawString(Font1, output, FontPos, Color.LightGreen,
// 0, FontOrigin, 1.0f, SpriteEffects.None, 0.5f);
spriteBatch.DrawString(Font1, output, FontPos, Color.LightGreen);
spriteBatch.End();

Wednesday, April 28, 2010

C++: cin & gets

hmmm.. couldn't get cin and gets to work together.
if cin is used before gets, gets will not wait for user input get the string, due to the "\n" character.
if it's the other way round, it will work. but this is not useful in the general sense if your program needs both string and number input.

so in general, use gets and then use "stdlib.h" data conversion functions, eg.: atoi, string -> int

Example:


/*
simple C++ program
*/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
using namespace std;

// a c++ program starts with main

int main()
{
int score;
int i;
char str[200];
char c;
c = 'c';

cout << "Enter a number from 1 to 10: " ;
gets_s(str);
score = atoi(str);

cout << "Enter your name: ";
gets_s( str);
for(i = 0; i<score; i++){
cout << c <<"++ is cool and so is " << str << "; score: " << score << "\n";
}
return 0;
}

Saturday, March 27, 2010

panoramic pic - 1st attempt


sigh.. took the shots in a rush with a baby in the babybjorn tugging at the camera.
exposure inconsistent, horizon tilted, people moving and thus at different locations in different shots, etc.

Sunday, February 07, 2010

3ds max plugin wizard with visual studio 2008 express

1a. Copy the 3ds "maxsdk" to D:\ drive or other location where there are no user permission issues.

1. Open the 3dsmaxPluginWizard.vsz file (in the 3dsmaxPluginWizard directory root) in a text editor and edit the ABSOLUTE PATH parameter to reflect the new location of the 3dsmaxPluginWizard root directory. Do not add a backslash after the directory name.

Param="ABSOLUTE_PATH = [Absolute Path Location of 3dsmaxPluginWizard Root Directory]"

1b. Edit 3dsmaxPluginWizard.vsz with a text editor, eg.: Notepad.
change line 2: Wizard=VsWizard.VsWizardEngine.9.0

2. Copy the following files from the 3dsmaxPluginWizard root to the 'VC\VCProjects' directory under your Visual Studio installation (e.g. C:\Program Files\Microsoft Visual Studio 9.0\VC\VCProjects):

3dsmaxPluginWizard.ico
3dsmaxPluginWizard.vsdir
3dsmaxPluginWizard.vsz

If you are using Visual Studio Express Edition, you need to copy the files listed above to the 'VC\Express\VCProjects' folder.


3. At this point the 3ds Max Plugin Wizard project should appear under File menu:New:Projects:Visual C++ Projects in Visual Studio.

CSS: rounded edge / corner box






CSS:

.mainbody {
border-right-width: 1px;
border-left-width: 1px;
border-right-style: solid;
border-left-style: solid;
border-right-color: #CCC;
border-left-color: #CCC;
padding-right: 10px;
padding-left: 10px;
}
.topcenter {
border-top-width: 1px;
border-top-style: solid;
border-top-color: #CCC;
}
.bottomcenter {
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #CCC;
height: 4px;
}
.topleft {
background-image: url(images/corners_topleft.gif);
background-repeat: no-repeat;
background-position: left top;
height: 5px;
width: 5px;
float: left;
}
.topright {
background-image: url(images/corners_topright.gif);
background-position: right top;
float: right;
background-repeat: no-repeat;
height: 5px;
width: 5px;
}
.bottomright {
background-image: url(images/corners_bottomright.gif);
background-repeat: no-repeat;
background-position: right top;
float: right;
height: 5px;
width: 5px;
}
.bottomleft {
background-image: url(images/corners_bottomleft.gif);
background-repeat: no-repeat;
background-position: left top;
height: 5px;
width: 5px;
float: left;
}
.topbottom {
height: 5px;
}


HTML:

<div>
<div class="topbottom">
<div class="topleft"></div>
<div class="topright"></div>
<div class="topcenter"></div>
</div>
<div class="mainbody">content</div>
<div class="topbottom">
<div class="bottomleft"></div>
<div class="bottomright"></div>
<div class="bottomcenter"></div>
</div>
</div>

Monday, January 25, 2010

Maya Plugin wizard for Visual C++ express edition 2008 setup

1. Unzip the MayaPluginWizard2.0.zip file in the maya installation folder, eg.: C:\Program Files\Autodesk\Maya2008\devkit\pluginwizard

2. Copy the following files to the "C:\Program Files\Microsoft Visual Studio 9.0\VC\Express\VCProjects" directory:
MayaPluginWizard.vsdir
MayaPluginWizard.vsz
MayaPluginWizard.ico

2b. Edit MayaPluginWizard.vsz with a text editor, eg.: Notepad.
change line 2: Wizard=VsWizard.VsWizardEngine.9.0

2c. create a folder "MayaPlugInWizard" in "C:\Program Files\Microsoft Visual Studio 9.0\VC\Express\VCProjects"

2d. move "MayaPluginWizard.vsdir" into this new folder.

3. Copy the "MayaPluginWizard" directory to "C:\Program Files\Microsoft Visual Studio 9.0\VC\VCWizards".

4. Start Microsoft Visual Studio 8 and invoke File -> New -> Project -> Visual C++ Projects and select MayaPluginWizard.

5. Enter a name and solution name and select the OK button.

6. Fill in the information for the "Plug-in setup" screen and then select the "Plug-in type" and "Included libraries" links to also enter the required information.

7. The project will be created and then the solution can updated and built.

Simple Stereo 3d Anaglpyh example


Download FLA

import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.utils.*;

// Picture is a movie clip symbol in the Library
var loader:Picture = new Picture();
var loader2:Picture = new Picture();
var scene:Sprite = new Sprite();

// for drawing scene from left eye view
var left:Bitmap = new Bitmap();
// for drawing scene from right eye view
var right:Bitmap = new Bitmap();
// background for correct blending
var bg:Sprite = new Sprite();

var leftData:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);
var rightData:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);

var distance:Number = 4; // left-right eye distance


init();
prepareStereo();

function prepareStereo():void
{
left.blendMode = BlendMode.SCREEN;
// right eye = green and blue channel
right.transform.colorTransform = new ColorTransform(0, 1, 1, 1);
// left eye = red channel
left.transform.colorTransform = new ColorTransform(1, 0, 0, 1);
left.bitmapData = leftData;
right.bitmapData = rightData;
setBackground();
this.addChild(right);
this.addChild(left);
// set the UI textbox and label to the top
this.setChildIndex(ui_mc, this.numChildren-1);
}
function setBackground(color:int = 0):void{
bg.graphics.beginFill(color);
bg.graphics.drawRect(-2000, -2000, 4000, 4000);
}
function init():void{
loader.x = 200;
loader.y = 200;
loader2.y = 200;
loader2.z = 300;
stage.addEventListener(MouseEvent.MOUSE_MOVE, move);
this.addEventListener(Event.ENTER_FRAME, update);
scene.addChild(bg);

scene.addChild(loader2);
scene.addChild(loader);
ui_mc.distance_txt.text = String(distance);
}
function update(e:Event):void{
// clear screen
rightData.fillRect(rightData.rect, 0xFFFFFF);
leftData.fillRect(rightData.rect, 0xFFFFFF);
distance = Number(ui_mc.distance_txt.text);
loader.x -= distance / 2; // move scene to the left for right eye
loader2.x -= distance / 2;
rightData.draw(scene);
loader.x += distance; // move scene to the right for left eye
loader2.x += distance;
leftData.draw(scene);
loader.x -= distance / 2; // move scene back to original position
loader2.x -= distance / 2;
}
function move(e:MouseEvent):void
{
loader.rotationY = (mouseY*2/stage.stageHeight - 1) * 60;
loader2.rotationY = (1-mouseY*2/stage.stageHeight) * 60;
loader.x = stage.stageWidth - mouseX;
loader2.x = mouseX;
}

Saturday, January 16, 2010

EasyPHP issues with Windows 7

Thanks to Ryan for the following post:
http://ryan.rawswift.com/2009/09/20/easyphp-on-64-bit-windows-7-how-to-fix-apache-and-mysql-problem/

summary of the above post:
issue 1 for Apache:
Apache cannot be runned: another Web server use the Web port
or port is blocked by firewall.
solution:
- Click the EasyPHP icon beside “Apache” button.
- Click “Configure” then click “EasyPHP“.
- Uncheck “Check server’s TCP port before starting” then click “Apply” button and then “Close” button.
- Click “Apache” button and then click “Start“.

issue 2 for MySQL:
Unexpected end of MySql... See log file?
solution:
- Go to “Computer“, open/view Drive C, then double click “Program Files (x86)“.
- Right click on “EasyPHP5.3.0” folder then click “Properties“.
- On “Security” tab click “Edit…” button.
- Select the user that you are currently using.
- Under “Permissions for Users” box, tick “Full control” on “Allow” column.
- And then click “OK” button to apply the changes.

Thanks, Ryan. it works for me.

Friday, January 08, 2010

Wednesday, January 06, 2010

FlashVars: sending variables into Flash from HTML/PHP

in HTML containing SWF:
...
AC_FL_RunContent(
...,
'flashVars','myVariable=<?php echo((isset($_GET['myVariable'])) ? $_GET['myVariable'] : ""); ?>'
); //end AC code

...
<param name="movie" value="live_stream.swf?myVariable=<?php echo((isset($_GET['myVariable'])) ? $_GET['myVariable'] : ""); ?>" />
<embed src="live_stream.swf?src=<?php echo((isset($_GET['myVariable'])) ? $_GET['myVariable'] : ""); ?>" ... >

in FLA/AS:
access variable thru:
this.loaderInfo.parameters["myVariable"]

Monday, December 21, 2009

Sunday, December 13, 2009

Wiimote interactive art




Plumbing experience - changing fill valve of toilet bowl




It all started with water leak from the back of the toilet bowl. then further investigation proved that the bottom inlet valve where the water enters to fill the toilet bowl after a flush is not functioning after 6 yrs of usage. somehow the water will seep in and water level will go beyond the drainage hole at the back hence the wet toilet floor at the back of the toilet bowl.

so gotta go spend $12 on the new valve to replace the original Fluidmaster. then realise need a bigger plier so spend another $18 to get the big big pliers to unscrew that white plastic nut at the bottom of the valve.

so the procedure can be found on youtube:


now to wait til next day to see if new valve is working fine

Monday, November 02, 2009

Flex: K-means algorithm in AS3

Move mouse within white canvas to collect mouse (x, y) data.
Enter the number of clusters to group the data.
Click "Cluster" to cluster mouse data
Click "Reset" to clear all previous data



url: http://psalmhundred.net/experiment/gesture/GestureApp.html

Sunday, November 01, 2009

Flash, AIR, ActionScript: File & FileStream

Cannot write to filesystem at File.applicationDirectory
But yet you can write using File.applicationDirectory.nativePath

To serialise an object of a custom class,
1) use flash.net.registerClassAlias( aliasName:String, classObject:Class)
to register the class before writing or reading
2) implement IExternalizable to your custom class
- readExternal(input:IDataInput):void
- writeExternal(output:IDataOutput):void
- Alternatively, you can use public fields in the custom class. But that is not entirely recommended for real world application.


import flash.filesystem.*;
import flash.net.*;

var a:A = new A();
...
...

function write():void{
registerClassAlias("A", A);
fileStream.open(file, FileMode.UPDATE);
fileStream.writeObject(a);
fileStream.close();
}
function read():void{
fileStream.open(file, FileMode.READ);
var o:A = fileStream.readObject() as A;
o.c();
fileStream.close();
}

/********************
class A
********************/
import flash.utils.*;

public class A implements IExternalizable
{
var b:int = 10;
public function c():void{
trace(b);
}
public function readExternal(input:IDataInput):void
{
b = input.readInt();
}
public function writeExternal(output:IDataOutput):void
{
output.writeInt(b);
}
}