POV-Ray : Newsgroups : povray.programming : POV-Ray C++? : Re: POV-Ray C++? Server Time
28 Apr 2024 04:43:07 EDT (-0400)
  Re: POV-Ray C++?  
From: David Buck
Date: 12 Feb 2012 11:50:47
Message: <4f37ede7$1@news.povray.org>
MiB wrote:
> Warp <war### [at] tagpovrayorg> wrote:
>> MiB <nomail@nomail> wrote:
>>> However, a quick survey reveals POV-Ray itself is not written in a contemporary
>>> object-oriented style; a lot of pointers to structs are handed around, functions
>>> manipulating data structures are on a global level and not members of classes.
>>   Could you give some clarifying examples of this, as well as a suggestion
>> of how it should be done better?
> 
> Pretty much the first file I touched was
> povwin-src-3.7-RC3\source\backend\scene\objects.h
> 
> Here, object types and properties are defined by flag values, operations on
> flags are preprocessor macros, operations on objects (including
> copy-construction and destructors!) are global functions instead of members of
> the Object class.

When I wrote DKBTrace originally, I had already been doing Smalltalk 
programming for a few years and was quite familiar with object oriented 
concepts.  Smalltalk obviously wasn't a good candidate language for 
implementing DKBTrace (sadly) and C was the only real alternative.

As such, you'll find that parts of the code do have an object oriented 
spin to them.  Take cones, for example.  In cones.cpp you'll find:

METHODS Cone_Methods =
{
   All_Cone_Intersections,
   Inside_Cone, Cone_Normal, Default_UVCoord,
   (COPY_METHOD)Copy_Cone, Translate_Cone, Rotate_Cone, Scale_Cone, 
Transform_Cone,
   Invert_Cone, Destroy_Cone
};

This is a virtual table of functions that allows call points to 
polymorphically call methods on objects without knowing the types of the 
objects.

This approach is difficult to maintain and wasn't used for other parts 
of the rendering system like vectors and textures.

Re-writing POVRay in C++ would probably be a good idea but obviously a 
lot of work. I would suggest staying away from some of the more 
difficult C++ concepts like multiple inheritance and operator 
overloading if you can.  I would agree to operator overloading for 
vectors and matrices since they make the syntax much nicer.  I'm not a 
fan of templates, but that's just my opinion.

David Buck


Post a reply to this message

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