Posts Tagged haxe

Triangle Islands : opengl + haxe

Introduction

I was looking around for a neat demo app to show off Haxe Archetype ’s new opengl template when I came across this really nice description of the olde triangle mountain algorithm .

The basic idea is to subdivide triangles and randomly move vertices up or down like this really nice diagram shows:

Splitting up Triangles and Making them Mountains

OK…
so maybe that looks a little confusing… but the text makes it really clear: split each triangle into 4 subtriangles. Sometimes, likeGroo , I’m a little slow of mind, so I drew a little picture to help me out:
From this, my brain part could pretty directly come up with:
 t[ 0 ] =  pt1, mid1, mid3
 t[ 1 ] = mid1,  pt2, mid2
 t[ 2 ] = mid3, mid2,  pt3
 t[ 3 ] = mid1, mid2, mid3
It looks likethis inhaxe .

Avoid the Gaps

So far so good! Split up the triangles! Raise/Lower those vertices! But…

BEWARE!

If you just start jacking around willy-nilly (or even willy+nilly [untested with willy±nilly]), you might not notice that when it’s time to split ”t[1]” and and ”t[3]” they are ”’both”’ gunna split the segment that connects ”mid1” and ”mid2”.

Lawd help you if you raise that pt in one and lower it in the other… or even raise it by different amounts: you will gap yourself up good and you
won’t like it.

It will look something like this:
and noone will think you are cool… Not even mom and dad.

My solution is pretty uncool actually:MidPointBuddy has a getMidPoint which returns the midpoint for any segment and keeps track of them in a hash table.

Simple, but effective… but lame.

Some minor openGL points

If you know me or if you have read any of this you probably know that I completely and shamelessly rip off everyone all the time and never do my own work.

Occassionaly I might throw together some crappy third rate ascii art:
/*  p1              p2
      .------------.
       \` .         \
        \   ` .      \
         \     ` .    \
          \        ` . \
        p4 .------------. p3  */
var p1 = new Pt3( -f, 0, -f );
var p2 = new Pt3(  f, 0, -f );
var p3 = new Pt3(  f, 0,  f );
var p4 = new Pt3( -f, 0,  f );
but mostly I just rip everything off from the internet and never make any sort of contributions to anything.
This is the case with the app that drives this mess. “Borrowed” it from thexinf gang .
Though I may have made some teensy changes.

Here is another example… I used to have some code like this a billion years ago, but I have no idea where it is now… probably on some thumb drive…

Luckily, there is no point in knowing of remembering anything anymore and with the help of Steve Baker (who I’ve never met, but I hear is very nice), I cobbed something likethis together:
GL.shadeModel( GL.FRONT_AND_BACK );
GL.enable( GL.LIGHTING );
GL.enable( GL.COLOR_MATERIAL );
GL.colorMaterial( GL.FRONT_AND_BACK, GL.AMBIENT_AND_DIFFUSE );
GL.enable( GL.LIGHT0 );
Put that together with alittle :
e1 = p1 - p2;
e2 = p3 - p2;
normal.cross( e1, e2 ).normalize();
...
cross(e1,e2) {
    this.x = ( e1.y * e2.z - e1.z * e2.y );
    this.y = ( e1.z * e2.x - e1.x * e2.z );
    this.z = ( e1.x * e2.y - e1.y * e2.x );
    return this;
}
sprinkle in a little:

to taste and off it goes.

Go get it and run it! I’m not charging you for it!

I know you have already download and installed haxe and must have subversion installed…
 % svn checkout http://brianin3d-triangle-mountain.googlecode.com/svn/trunk/ brianin3d-triangle-mountain-read-only
 % cd brianin3d-triangle-mountain-read-only
 % haxe compile.hxml
 % ./app
I apologize for the controls: x,y,z,q,r

Check it out and see how easy it is to have a lot of fun withopengl andhaxe .

Got a better idea for a project? Fire it up with Haxe Archetype ’s new flash tip:

Holler!

Links

  • the code
  • dhood’s blog
  • Haxe Archetype
  • opengl for Haxe
  • Basic OpenGL Lighting
  • Saddy Faces?

    Sometimes things don’t work out like you’d like… I know… it’s a bummer…

    XF86VidModeQueryExtension

    Back when I first wrote this, this happened on my workstation, but not on my desktop:
    Called from opengl/GLU.hx line 271
    Called from GLFW__impl.hx line 16
    Uncaught exception - load.c(232) : Failed to load library : /usr/lib/haxe/lib/opengl/0,2,0/ndll/Linux/opengl.ndll (/usr/lib/haxe/lib/opengl/0,2,0/ndll/Linux/opengl.ndll: undefined symbol: XF86VidModeQueryExtension)
    

    they were both running Ubuntu 8.10, both with NVidia drivers… The problem ”’only”’ occurred on the workstation after some number of updates (and in 9.x) the problem magically disappeared…

    osx fix

    When I first ran this thing I got some junk like:

    DLLLoader.hx:50: added to Env: DYLD_LIBRARY_PATH Value /usr/lib/haxe/lib/opengl/0,2,0/ndll/Mac
    Called from opengl/GLU.hx line 271
    Called from GLFW__impl.hx line 16
    Uncaught exception - load.c(232) : Failed to load library : ./opengl.ndll (dlopen(./opengl.ndll, 1): Library not loaded: libglfw.dylib
      Referenced from: /Users/brian/tmp/misc/brianin3d-triangle-mountain-read-only/opengl.ndll
      Reason: image not found)
    

    I fixed it like this: DYLD_LIBRARY_PATH=/usr/lib/haxe/lib/opengl/0,2,0/ndll/Mac:/Developer/SDKs/MacOSX10.5.sdk/usr/lib ./app

    ~

    Leave a Comment

    haxe ragdoll physics

    I had always thought about physics simulation in a particular fixed way. Even though I knew games physics were not physic simulations. Happily, the other day I was looking for information on Skeletal Animations, I got a pointer to Advanced Character Physics which talked about a best-effort relaxation algorithm that got me really excited!

    I know… but it did. Yes, I’m that guy.

    The article is super clear and finally I got it.

    But why bore you with the details of my implementation, when I can bore you with my demo instead!

    rag it out

    rag it out

    Did you miss the link?

    CLICK HERE FOR THE DEMO!

    you want it? you got it!

    % svn checkout http://brianin3d-stickler.googlecode.com/svn/trunk/ brianin3d-stickler-read-only
    % cd brianin3d-stickler-read-only/
    % haxe compile.hxml

    Pull up stickler.swf in your browser and rag it out!

    Leave a Comment

    haXe 2.01 Released

    Dang! How did I miss this? Two weeks ago… haXe 2.01 Released!

    % wget http://haxe.org/file/hxinst-linux.tgz
    % tar xfz hxinst-linux.tgz
    % sudo ./hxinst-linux
    % haxe -h 2>&1 | grep ^Haxe
    Haxe Compiler 2.01 - (c)2005-2008 Motion-Twin
    

    The only issue with the installer is it doesn’t have a “hell yeah” option…. imho… :-D

    Leave a Comment

    haxe archetype

    This page is out of date! The current page is over here!

    Start new haxe projects fast!

    Installation + Quickstart

    % sudo haxelib install archetype
    % haxelib run archetype create -artifactId=myProject -packageName=us.versus.them -version=1.0
    % cd myProject
    % haxe compile.hxml
    % ls myProject.swf
    myProject.swf
    

    Introduction

    This is based on the idea of the maven archetype plugin.

    In maven this works something like this:

    mvn \
            archetype:create                   \
            -DartifactId=myProject             \
            -DgroupId=myGroup                  \
            -DpackageName=us.versus.them       \
            -Dversion=1.0.0-SNAPSHOT
    

    The syntax is similar:

    haxelib run                               \
            archetype                         \
            create                            \
            -artifactId=myProject             \
            -packageName=us.versus.them       \
            -version=1.0
    

    The arguments artifactId and packageName are mandatory.

    If version is not set, it will default to 1.0.

    In this example, the archetype would create a directory structure like so:

            myProject/
            |-- Main.hx
            |-- Test.hx
            |-- haxelib.xml
            |-- compile.hxml
            |-- test.hxml
            |-- tests
            |   `-- AppTest.hx
            `-- us
                `-- versus
                    `-- them
                        `-- myProject
                            `-- App.hx
    

    Despite the name, this is not nearly as flexible as maven’s archetype plugin. In order to add more archetypes, you would actually have to modify the source code for this module.

    Maybe someday, it can grow into a real equivalent. For now, it is better than nothing.

    Compilation and package

    % haxe compile.hxml
    % cd ..
    % zip -r myProject.zip myProject
    

    You can install them into your local haxe library ala:

    % haxelib test myProject.zip

    running testcases

    Running unit tests is a little clunky…

    % haxe test.hxml && neko test.n
    

    Unfortunately, you have to update Test.hx to add new tests. They can live in the tests subdirectory to keep them separate from the main code.

    source

    I put the source such as it is where you can get it and play wif it like it was some sort of ball or barbie!

    Comments (3)

    gen-hx-classes papervision3d

    After reading [haXe] Fisix + haXe = FisaXe? hehe, I started to wonder if I couldn’t use a similar trick to make papervision3d.

    Though I was not able to get a pure haxe solution, I did get a happy ending

    Updating papervision3d

    ActionScript3 pointed out that the version of papervision3d he ported was old and that it would probably be worthwhile to grab a newer version

    I thought about checking out a copy from SVN, but I know the sort of stuff you tend to get from checking out from the head… :-P

    So I decided to go with what looked to the the last official release, version 1.5 from Papervision3D_1_5.zip.

    % mkdir /home/brian/tmp/pv3d
    % cd /home/brian/tmp/pv3d
    % unzip Papervision3D_1_5.zip
    % ls PV3D_1_5/src
    com  fl  livePreview  org

    Cool…

    flex builder for linux

    Word on the street is that the A3 compiler from flash is still faster than haxe.

    So… I went to and grabbed a copy of the flex builder alpha for linux.

    The install wanted an eclipse directory with a “configuration” subdirectory and barked at me… I’m not really an eclipse guy, so whatever. Maybe I will hook it up later…

    Here is what it looked like:

    % chmod 755 flexbuilder_linux_install_a3_033108.bin
    % ./flexbuilder_linux_install_a3_033108.bin
    % export PATH=${PATH}:${HOME}/data/Adobe_Flex_Builder_Linux/sdks/3.0.0/bin/
    % which mxmlc
    /home/brian/data/Adobe_Flex_Builder_Linux/sdks/3.0.0/bin//mxmlc

    Sweet… now I can get that AS3 fanciness I keep hearing about!

    mxmlc

    This actually had me scratching my noggin… The original post had said:

    mxmlc -include-libraries /AS3_src/Fisix/Bin/FisixEngine.swc -file-specs Test.as -output ./FisixLib.swf  -benchmark=true

    Obvious Test.as is something I don’t have and I also don’t have a swc and I won’t bore you with how I came up with this bit of madness:

    % cd /home/brian/tmp/pv3d
    % mkdir tmp
    % cd tmp
    % find /home/brian/tmp/pv3d/PV3D_1_5/src -type f -name "*.as" > nice.as.txt
    % echo "package {" > Test.as
    % cat nice.as.txt | cut -f1 -d. | sed 's,.*src/,import ,;s,/,.,g;s,$,;,'  >> Test.as
    % echo "public class Test {" >> Test.as
    % cat nice.as.txt  | cut -f1 -d. | sed 's,.*/,,;s,.*,public var tmp_& : &;,' >> Test.as
    % echo "} }" >> Test.as

    Of course that’s not exactly how I did it, but it was just as painful and used the same methodology.

    So by now you are probably shaking your head and laffing, going “ok, bright-boy! now echo me up an swc file!”

    Not nice…

    Happily, I got some command line help from a guy I don’t know in Japan, so that I was able to hookup:

    %  mxmlc -source-path ${HOME}/tmp/pv3d/PV3D_1_5/src -file-specs Test.as -output Papervision3d.swf

    Kabloom! It dumped out a bunch gobble-de-gook.

    Luckily, yours-truly is an old hand at ignoring compiler errors… A little of ye olde clickety-clack… and I had version of Test.as that would compile.

    I did it like this:

    % grep PV3D_1_5/src mxmlc.errors.compiling.PV3D_1_5.txt | cut -f1 -d\( | sed 's,.*/,,;s,.as$,,' | sort -u | sed 's,^,tmp_,'
    tmp_CompositeTriangleCuller
    tmp_DepthTriangleCuller
    tmp_InteractiveWireframeMaterial
    tmp_LivePreviewParent.as: Error: A file found in a source-path must have the same package structure 'livePreview', as the definition's package, 'fl.livepreview'.
    tmp_PV3DColladaScene
    tmp_Stars

    Look, maw! I’m UNIX hackin’! I’m UNIX hackin’! Got that one odd-man-out…

    Comment those lines out:

    //public var tmp_CompositeTriangleCuller : CompositeTriangleCuller;
    //public var tmp_DepthTriangleCuller : DepthTriangleCuller;
    //public var tmp_InteractiveWireframeMaterial : InteractiveWireframeMaterial;
    //public var tmp_PV3DColladaScene : PV3DColladaScene;
    //public var tmp_Stars : Stars;
    //public var tmp_LivePreviewParent : LivePreviewParent;

    Next thing you know:

    %  mxmlc -source-path ${HOME}/tmp/pv3d/PV3D_1_5/src -file-specs Test.as -output Papervision3d.swf
    Loading configuration file /home/brian/data/Adobe_Flex_Builder_Linux/sdks/3.0.0/frameworks/flex-config.xml
    Papervision3d.swf (168851 bytes)

    And now we know!

    And knowing is half the battle…

    Let’s fight on…

    gen-hx-classes

    The next piece of good advice is that we can use

    % haxe --gen-hx-classes Papervision3d.swf

    Yeah… sure it spewed a bunch of madness, but let it!

    It also generated a lot of good stuff!

    % find hxclasses -name "*.hx" | wc -l
    287

    Kind of a lot of stuff.. the original library only had 85 .as files… hummm… thanks?

    trying it on

    % cp Papervision3d.swf /tmp
    % cp -r hxclasses /tmp
    %  cat TestHaxePv3d.hxml
    -main TestHaxePv3d
    -swf TestHaxePv3d.swf
    -swf-version 9
    -swf-lib /tmp/Papervision3d.swf
    -cp /tmp/hxclasses
    % haxe TestHaxePv3d.hxml
    TestHaxePv3d.hx:19: characters 0-47 : Class not found : org.papervision3d.core.utils.FPSCounter

    Which is actually ok… I reused my demo from before… clickety-clack…

    % haxe TestHaxePv3d.hxml

    Yup… it gacked up more “Unknown opcode 0×59″ hairballs! but… lookit!

    % ls *swf
    TestHaxePv3d.swf

    Or better yet! Don’t bother!

    Cuz it’s just a blank blue-ish screen!

    Haha! It doesn’t really make me feel any better that Asger Ottar Alstrup got stuck at pretty much the same point…

    When I asked him about it, he said he did get it to work:

    Hi,
    
    Yes, I got it to work just fine. Just make a .as file referencing the classes you need, compile that to a papervision.swf file, then
    
    haxe --gen-hx-classes papervision.swf
    
    generates the classes, and everything works fine. Remember to add a "-cp" switch to point to the generated files, and link in the papervision.swf file using "-swf-lib". (I use swfmill to bundle a bunch of .swf's together to one .swf and then link that into the final .swf, but it also works if you just directly link in the papervision.swf file.)
    
    Regards,
    Asger
    

    So… I dunno

    Bummer… I tried everything all over again trying to use the 2.0.1 version of mxmlc, but with the same result.

    Silver Lining

    Though I was originally hoping to be able to papervision3d via haxe, I finally did end up with a solution that works

    % wget http://www.andrestubbe.com/downloads/papervision3d/ExampleSpherePrimtive.as
    % mxmlc -source-path ${HOME}/tmp/pv3d/PV3D_1_5/src -file-specs ExampleSpherePrimitive.as -output exampleSpherePrimtive.swf

    Sure… it’s actionscript, but yeah the compiler is proprietary, but … eh.. at least there is some way forward.

    It just wasn’t the way I wanted… boo+hoo=moving on

    Time to get my AS3-fancy on!

    Comments (1)

    Older Posts »