POV-Ray : Newsgroups : povray.general : Some musings about POV-Ray and Java... : Some musings about POV-Ray and Java... Server Time
10 Aug 2024 15:20:00 EDT (-0400)
  Some musings about POV-Ray and Java...  
From: Johannes Hubert
Date: 25 Nov 1999 14:52:36
Message: <383d9384@news.povray.org>
No, not another try to do a "platform" independent raytracer in Java... :-)

Today (while hanging up my laundry of all things!) I was musing about the
POV-Ray script language, and that it indeed does allow the programmer much
more freedom than modeler-tools, but that it also is quite an inelegant,
clumsy and limited language (as programming languages go), with, in parts, a
horrible syntax...

I then remembered, that I once saw a project of someone who had create a C++
class library so that you could then program a POV-Ray scene in C++. An idea
I think is quite good, but I guess it never caught on...

Then I thought, that this should be very doable in Java too:

Write a number of Java packages (as a library) so that you can then write a
POV-Ray scene in Java, making use of the many powerful constructs of that
language, that the POV-Ray script language is lacking (most of all classes,
different sorts of loops and nicer syntax without "#declare" and stuff).
This would work in such a way, that the Java program, once run, would create
a textfile (*.pov) with the real POV-Ray script, which would then be parsed
and rendered by the good ole POV-Ray engine.
Another advantage would be, that errors that otherwise could become obvious
only after a lengthy parsing time, would appear already at compile time or
at Java runtime. The resulting POV file would be a plain vanilla file
without #if, #whiles and such, and thus be quite fast to parse (I guess) and
guaranteed to be without parsing errors.

Anyone interested? Do you think that there would be people using such a
thing, or would everyone still simply continue using the POV-Ray script
(let's make the assumption that the Java-layer would allow you to program
every feature into POV-Ray that exists, that it would not hide stuff from
you like modelers do).

Thoughts?

Johannes.


P.S.
for those of you that already know Java, here an "off the top of my head"
example on how such a "Java-POV-Script" could look like (with the "hello
world" of raytracing ;-) :

import pov.textures.*;

class HelloWorld extends POVScene
{
    public static void main(String[] args)
    {
        add(new Sphere(0, 2.5, 0, 3, new TextureChrome()));
        add(new Plane(/*appropriate parameters for checkered plane*/));

        add(new PointLight(...));

        add(new Camera(...));

        renderScene("HelloWorld.pov");

        // the previous command would create the POV-script and
        // start POV-Ray via the command line to render it.
    }
}

Obviously, the above example uses none of the advantages Java can give, but
you'll get the idea...
If not, think about the animation possibilities:

import pov.textures.*;

class HelloWorld extends POVScene
{
    public static void main(String[] args)
    {
        add(new Sphere(0, 2.5, 0, 3, new TextureChrome()));
        add(new Plane(/*appropriate parameters for checkered plane*/));

        add(new PointLight(...));

        Camera camera = new Camera(...);
        add(camera);

        // Fly the camera around the sphere (in 1 degree steps)
        // and render one image for each position:

        double x, z;
        for (int i = 0; i < 360; i++) {
            x = cos(i / 180.0 * PI) * 20;
            z = sin(i / 180.0 * PI) * 20;
            camera.setPosition(x, 5, z);

            renderScene("HelloWorld" + i + ".pov");
        }
    }
}

(For Java purists: Assume that "cos", "sin" and "PI" have been defined as
member-functions of "POVScene" to create a nicer syntax, they are simply
calls/references to Math.cos, Math.sin and Math.PI.)


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.