Archive for the ‘OS X’ Category

Unproject with useProjectionMatrix = true

Wednesday, April 29th, 2009

I just updated Papervision3D to allow the CameraObject3D#unproject method to work when CameraObject3D#useProjectionMatrix = true.

Papervision3D has two methods of ‘projecting’ vectors onto the screen:

  1. useProjectionMatrix = false, this is the default ‘fast’ method
  2. useProjectionMatrix = true, this is the method where projection is done by a matrix

Note that Papervision3D switches to method #2 in ‘ortho mode’.

So what is the difference exactly between these two kinds of projection? First we need to define what projection is. Projection is what adds ‘perspective’ to a scene and makes sure your scene fits to the viewport. Its the last step in the so-called ‘render pipeline’.

We can derive the ‘fore shortening’ effect of perspective in several ways. Method #1 is simple, effective and fast. It uses the camera’s focus and zoom values. Method #2 uses a more classic way of projection : it uses a dedicated matrix. Tech buffs: very much like OpenGL’s gluPerspective.

Andy Zupko has a great post on unproject using method #1.

We will discuss unproject using method #2, which works slightly different.

The difference is that when #useProjectionMatrix is set to true, then CameraObject3D#unproject returns a point in world-space, rather then a ray. Let me explain with some code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// we want to use a projection matrix
camera.useProjectionMatrix = true;
 
// '0' indicates we want a point on the near plane
var pointOnNearPlane : Number3D = camera.unproject( screenX, screenY, 0 );
 
// '1' indicates we want a point on the far plane
var pointOnFarPlane : Number3D = camera.unproject( screenX, screenY, 1 );
 
// Construct the ray's direction
var dir : Number3D = Number3D.sub( pointOnFarPlane, pointOnNearPlane );
 
// Normalize
dir.normalize();
 
// So, now you have a ray with its origin at 'pointOnNearPlane',
// and direction 'dir'

Optimization: could save some cycles by doing (*not* in ortho mode!, see below):

1
2
3
4
5
6
7
var camPosition : Number3D = new Number3D( camera.x, camera.y, camera.z );
// Construct the ray's direction
var dir : Number3D = Number3D.sub( pointOnFarPlane, camPosition );
// Normalize
dir.normalize();
// So, now you have a ray with its origin at the camera's position
// and direction 'dir'

Why can’t we use above optimization in ortho mode?
In perspective mode all ‘rays’ originate from the camera’s position: the ‘view cone’ has shape of a pyramid. Hence we can assume ‘pointOnNearPlane’ to coincide with the camera’s position.
In ortho mode however the ‘view cone’ has the shape of a cube, all rays are parallel. Hence we need to unproject *two* points to construct our ray.

Now simply follow Andy Zupko ’s post to drag objects around.
Or perform ‘picking’, or…

Update:
Created a little demo to visualize what I’m ranting about, check it out here

Mousewheel events in Flash on OS X

Wednesday, May 7th, 2008

The Flash Player on OS X currently lacks support for mousewheel events. This means that users cannot use their mousewheel on OS X, in the Floorplanner we use the mousewheel to easily zoom in to your Floorplan. After reading this post from pixelbreaker, I was inspired to implement this in the Floorplanner which was, in fact, very easy. I decided to only use the JavaScript class of pixelbreaker, which sends the mousewheel events to the Flash Player (on the Mac). In the Floorplanner ActionScript this event is handled by our own internal Event management system, which sends the Event to the reponsible part of the code. So thumbs up for pixelbreaker, for making this really easy to implement!

Installing Apache2 & PHP5 on OS X

Wednesday, January 16th, 2008

I found this great tutorial on how to install Apache2 and PHP5 on OSX.

Thanks a lot Maccius!

By the way, if you just want to use the Apache and PHP versions that come with OSX, read this post.

ASProject 0.1.92

Friday, April 13th, 2007

The issues with ASProject on win32 I reported are fixed with this rev.

Just do:
gem update asproject

Installing Ruby on Rails on OSX made easy

Thursday, April 12th, 2007

Thanks to Robby on Rails installing Ruby on Rails on my iMac was a piece of cake!

  • Download and install Xcode
  • Download and install DarwinPorts
  • Start up the Terminal
  • Modify the default bash profile with TextMate: sudo mate /etc/profile
  • Add /opt/local/bin to the PATH: PATH="/bin:/sbin:/opt/local/bin:/usr/bin:/usr/sbin"
  • Install Ruby with DarwinPorts with: sudo port install ruby rb-rubygems
  • Install Ruby on Rails and all its dependencies with: sudo gem install -y rails

ASProject

Tuesday, April 10th, 2007

Just checked ASProject.

AsProject is a tool set that dramatically simplifies the process of creating, sharing and growing a new ActionScript project

Installing is easy if you have Ruby/Gem installed:

gem install asproject
asproject MyProjectName
cd MyProjectName/project
rake

And presto!

Now run a unit-test:
rake test

Here’s a video demo.

Update:
found some issues with version 0.1.90 on win32:

  1. Need to change ‘mxmlc’ to ‘mxmlc.exe’ in mxmlc.rb#36 (located under /ruby/lib/ruby/gems/asproject/templates/ dir)
  2. Using as3 the default skin (a jpg) is corrupted, need to copy also from /templates to the project’s asset folder. I bet it’s some fopen using “r” (read) instead of “rb” (read binary) switch or something related.

AsUnit on OS X

Friday, March 23rd, 2007

I’m looking at AsUnit to start unit testing the Floorplanner. Aral Balkan has written a post AsUnit-X: AsUnit XUL UI for OS X on an easy way to get started on OS X. I’ll keep you posted on the progress!

Installing the Flash Debug Player on a Intel-based Mac

Friday, March 16th, 2007

Today i’ve had some trouble getting the Flash Debug Player working on my new iMac. I downloaded the content debugger for Intel-based Macs from the Adobe Flash Player Support Center and installed it. The problem was, it didn’t work…. no mm.cfg, no flashlog.txt

After some surfing i found out that the easiest way to get things working is to install the fabulous Firefox Add-on Flash Tracer from Alessandro Crugnola. Besides the add-on itself, it creates 2 files: flashlog.txt (HD/Users/username/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt) and mm.cfg (HD/Users/username/Library/Application Support/Macromedia/mm.cfg). This makes all the difference! All the traces of my flash movie are stored in the flashlog.txt file and are shown in the Flash Tracer (when pointing it once to the flashlog.txt file)

If you don’t want to install Flash Tracer you can create the mm.cfg file manually. It should look something like this:

ErrorReportingEnable=0
TraceOutputFileEnable=1
MaxWarnings=500

I believe you also have to create an empty flashlog.txt file manually, but i’m not sure. Hope this helps!