POV-Ray : Newsgroups : povray.advanced-users : Object Oriented POV code : Re: Object Oriented POV code Server Time
29 Jul 2024 02:34:47 EDT (-0400)
  Re: Object Oriented POV code  
From: David Wallace
Date: 12 Feb 2004 13:08:18
Message: <402bc112@news.povray.org>
I'm afraid my "objects" don't work quite that way.  I use them like this:
--- code ---
// Parametric variable form
//#version unofficial MegaPov 0.7;

#declare uMin = 0; // Minimum u value
#declare uMax = radians(90); // Maximum u value
#declare uNum = 41; // Number of points in u direction
#declare uWrap = 0; // u wraps around if != 0
#declare uSeed = 8266; // Random number seed for u parameter

#declare vMin = 0; // Minimum v value
#declare vMax = radians(356); // Maximum v value
#declare vNum = 90; // Number of points in v direction
#declare vWrap = 1; // v wraps around if != 0
#declare vSeed = 1425; // Random number seed for v parameter

#declare IsRnd = false; // True if random number used
#declare IsUV = false; // True if object is to be UV-mapped

#declare Smooth = 0; // Smooth flag

#declare Detail = "Partial"
/* Detail values
  Verbose = Line by line details
  Partial = Operations only
  Other = Filename only
*/

/* For all macro functions
 i = Current value of u parameter
 j = Current value of v parameter
 p = Current value of u variance (0...1)
 q = Current value of v variance (0...1)
 vc= Current 3D point
*/

// Optional functions

// point function
#macro pnt(i, j, p, q)
 #local r0 = 1.1;
 #local r1 = exp(cos(j));

 #local yp = r0*sin(i);
 #local xp = cos(i)*cos(j)*r1-exp(yp-0.35);
 #local zp = cos(i)*sin(j)*r1*.1;

 <xp, yp, zp>
#end
--- end code ---
To alter a property I simply use #declare or MegaPov's #set.  I use the
contained macros in the traditional POV-Ray fashion.  Like I mentionned
earlier, this trick is used to simplify macro calls and make variable macros
and functions available to them.  It's not classic C++ classes by a long
shot and it wasn't intended to be.

"Tek" <tek### [at] evilsuperbraincom> wrote in message
news:4029c7e1$1@news.povray.org...
> Maybe I'm misunderstanding you, but how does having each object as an
include
> file help? Or do you mean have each class as an include file?
>
> BTW, did you see the technique I posted in p.b.s-f? That sounds pretty
similar
> to what you're suggesting. It solves the problem of indirect function
> invocation, but but I still haven't found a nice way of defining
> structures/classes. Can your system do this?
>
> Basically I want to be able to do things like this:
>
> myMoveableObject = new Monkey; //Monkey is a class
> ...
> myMoveableObject.move(deltaTime);
> ...
> if ( myMoveableObject.position == invalid ) delete myMoveableObject;
>
> -- 
> Tek
> www.evilsuperbrain.com
>
>
> "David Wallace" <dar### [at] earthlinknet> wrote in message
> news:402907a4@news.povray.org...
> >
> > "Tek" <tek### [at] evilsuperbraincom> wrote in message
> > news:4025787d@news.povray.org...
> > > I've decided to have a go at creating a fairly complex scene file
based on
> > lots
> > > of autonomous entities with simple ai and physics. So, I've been
figuring
> > out
> > > tricks for writing pov scene code in an object-oriented manner.
> > >
> > > i.e. there basically needs to be some way of defining classes (I won't
do
> > > inheritance), with member variables and functions. And some system of
> > creating
> > > and destroying these on the fly. Oh, and persistent variables.
> > >
> > > Now, I think I've actually figured out a pretty decent way to do all
this,
> > just
> > > using the SDL. I'm happy to give details but I don't want to clog up
this
> > > message with all that info.
> > >
> > > But anyway, the reason I'm posting: I was just wondering has anyone
done
> > this
> > > before? Either within the SDL, or as a modification to pov to support
> > simple
> > > data structures and function callbacks?
> > >
> > > Oh, and do you think it should be oriented or orientated? ;)
> > >
> > > -- 
> > > Tek
> > > www.evilsuperbrain.com
> > >
> > >
> > My principal "object" is the #include file.  Each object definition,
> > including macros, variables, etc. can be placed in this file.
> >
> > If you want a macro to use the object, just use the filename as a string
> > parameter:
> >
> > #macro ObUser(iFile, oFile)
> >     #include iFile
> >     #open oFile
> >     ...
> >     #write oFile, Data
> >     ...
> >     #close oFile
> > #end
> >
> > I use this tactic frequently.  Macros that would otherwise use a large
> > number of parameters are greatly simplified by this method.  Macros,
> > functions, and primitives that might not otherwise be available as macro
> > parameters can be provided for this way.
> >
> > #include files also carry one extra benefit: you can add descriptive
> > comments and variable names that make code reading easier
> >
> > Try it some time.
> >
> >
> >
>
>


Post a reply to this message

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