Create Journals
Update Journals

Journals
Find Users
Random

Read
Search
Create New

Communities
Latest News
How to Use

Support
Privacy
T.O.S.

Legal
Username:
Password:

ClaudiusMaximus (claudiusmaximus) wrote,
@ 2008-06-29 16:58:00
Previous Entry  Add to memories!  Add to Topic Directory  Tell a Friend!  Next Entry

    ray42 as a Lua package using tolua

    ray42 was nice as it was, but I got fed up with having to recompile each time I wanted to render a new scene, and C++ isn't a particularly friendly scene description language. So I'm now using tolua to make a Lua package from the core of ray42, and it seems to work ok.

    This code:

    require("ray")
    require("materials")
    
    local s = nil
    for x = -1, 1 do for y = -1, 1 do for z = -1, 1 do
      local m
      if x*y*z == 0 then m = gold else m = cyan end
      local t = sphere3(m, 0.5):translate(v3(x,y,z)*1.5)
      if s ~= nil then s = s + t else s = t end
    end end end
    s = s:transform(rotate3(0.3,1,2) * rotate3(0.3,0,2) * rotate3(0.3,0,1))
    
    local l = Lights3:new(rgb(0.25,0.25,0.25))
    l:add(v3(-3,0,0), rgb(0.5,0.5,0.5))
    l:add(v3( 3,0,0), rgb(0.5,0.5,0.5))
    l:add(v3(0,-3,0), rgb(0.5,0.5,0.5))
    l:add(v3(0, 3,0), rgb(0.5,0.5,0.5))
    l:add(v3(0,0,-3), rgb(0.5,0.5,0.5))
    l:add(v3(0,0, 3), rgb(0.5,0.5,0.5))
    
    render3(s, l, 788, 576, 4/3, 2)

    generates this image:

    cube of spheres 3d

    One small tip when using tolua with recent versions of g++: activate the -Wno-write-strings flag to avoid drowning in a flood of:

    warning: deprecated conversion from string constant to 'char*'

    It is quite boring writing wrappers for ray42's C++ template classes because tolua doesn't seem to understand templates, maybe I should be using tolua++ or some other tool entirely.



(Read comments)

Post a comment in response:

From:
 
Username:  Password: 
Subject:
No HTML allowed in subject
 Don't auto-format:
Message:
Enter the security code below.


Notice! This user has turned on the option that logs your IP address when posting.

Allowed HTML: <a> <abbr> <acronym> <address> <area> <b> <bdo> <big> <blockquote> <br> <caption> <center> <cite> <code> <col> <colgroup> <dd> <dd> <del> <dfn> <div> <dl> <dt> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr> <i> <img> <ins> <kbd> <li> <li> <map> <marquee> <ol> <p> <pre> <q> <s> <samp> <small> <span> <strike> <strong> <sub> <sup> <table> <tbody> <td> <tfoot> <th> <thead> <tr> <tt> <u> <ul> <var> <xmp>
© 2002-2008. Blurty Journal. All rights reserved.