I find coding in haxe every day more enjoyable! I scripted my raytracer using hscript, so now scenes can be described and rendered directly in the browser.

The classes available for scripting are:

Primitive:

- new(position)

- position:Vector

- color:Vector

- difusse, specular, power: Float

Primitive -> Sphere:

- new(radius:Float, position:Vector)

Primitive -> Plane:

- new(normal:Vector, distance:Float)

Scene:

- setBackground(color:Vector)

- setDimensions(width:Float, height:Float)

- addPrimitive(p:Primitive)

- addLight(l:Primitive)

Vector:

- x, y, z:Float

The Math's methods and the trace function are also available.

There are some known bugs and I'm working on crashing them. I also plan to add shadows, reflection, refraction etc to the raytracer.

Here's an example script:

function rand(n1,n2){

return Math.floor(Math.random()*(n1-n2+1))+n2;

}

scene.eye.set(0, 0, -500);

scene.setDimensions(300, 300);

var i = 0;

var x = -50;

var y = 100.0;

var z = -100.0;

while(i<360){ var deg = i * Math.PI / 180.0; var s = new Sphere(20, new Vector(x += Math.cos(deg) * 50, y -= 15, z += Math.sin(deg) * 130)); s.color = new Vector(rand(0, 255), rand(0, 255), rand(0, 255)); trace(s.color); scene.addPrimitive(s); i += 30; } scene.addLight(new Primitive(new Vector(0, 500, -500)));

## 2009-08-07

## 2009-08-04

### raytracing in haxe

As I've started to learn haxe, I wrote a very basic raytracer

It can go real-time too, if you dont care much about the image quality. And here are the sources.

It can go real-time too, if you dont care much about the image quality. And here are the sources.

Subscribe to:
Posts (Atom)