POV-Ray : Newsgroups : povray.advanced-users : Povray Parser for Moray Server Time
29 Jul 2024 18:26:47 EDT (-0400)
  Povray Parser for Moray (Message 1 to 10 of 10)  
From: Keith Hull
Subject: Povray Parser for Moray
Date: 17 Oct 2001 12:20:40
Message: <3bcdafd8$1@news.povray.org>
Hi All,

I'm currently in the process of writing a Povray to Moray Parser, most of
the objects can be imported and csg's, I have a few things to sort out like
textures and declare statements. However my biggest problem is how I convert
Povray object vectors to Moray Scale/Rotate/Translate vectors e.g. for a
cone...
// How do I convert from this (Pov format)......
cone
{
 <-2,-1,1>, 4,
 <5,-6,4>, 2
  scale <0.5,0.5,0.5>
  rotate <12,36,8>
  translate  <-5,-1,1>
}

// to this (Moray format)......
cone {
  <0,0,0>, 4,
  <0,0,1>, 2
//  scale <x,y,z>
//  rotate <x,y,z>
//  translate  <x,y,z>
}
I can't change the base/cap vectors only the scale/rotate/translate vectors.
Does anybody have any ideas? For the translate I assume I can add the base
vector and the cone translate to get a Moray translation vector, but I'm
stumpted on the scale and rotate vectors.

Any help would be appriciated.....

Many Thanks,

Keith

BTW is this the best place to post this....... maybe it should have gone to
Pov programming?


Post a reply to this message

From: Peter Popov
Subject: Re: Povray Parser for Moray
Date: 17 Oct 2001 16:47:30
Message: <dlqrstombm0tu1mgo4gl8gasl10e6364ls@4ax.com>
On Wed, 17 Oct 2001 17:22:46 +0100, "Keith Hull"
<kei### [at] totalisecouk> wrote:

>I'm currently in the process of writing a Povray to Moray Parser

Wow!

>most of the objects can be imported and csg's, 

WOW!

>I have a few things to sort out like textures and declare statements. 
>However my biggest problem is how I convert Povray object vectors to 
>Moray Scale/Rotate/Translate vectors e.g. for a cone...

With the proper matrix you can define any affine transformation.
However, in order to define a local coordinate system on the cone, you
need more than just two points. In general, you need 4 points, but you
can pass with three (both apex points and another point on the
circumference on the larger base) if you know it's a straight cone.

In any case, once you have the matrix, it *might* be possible to
convert it to a triple of scale/rotate/translate matrices by matrix
division (inverse multiplication, that is). How, I don't know, but
I'll think about it tomorrow, when I've had some sleep.

Maybe I'm totally rambling here... our Neo would know best :)


Peter Popov ICQ : 15002700
Personal e-mail : pet### [at] vipbg
TAG      e-mail : pet### [at] tagpovrayorg


Post a reply to this message

From: Ron Parker
Subject: Re: Povray Parser for Moray
Date: 17 Oct 2001 16:56:20
Message: <slrn9srs3m.e53.ron.parker@fwi.com>
On Wed, 17 Oct 2001 23:43:47 +0300, Peter Popov wrote:
>In any case, once you have the matrix, it *might* be possible to
>convert it to a triple of scale/rotate/translate matrices by matrix
>division (inverse multiplication, that is). How, I don't know, but
>I'll think about it tomorrow, when I've had some sleep.

Provided you know it came from a given sequence of scale/rotate/translate
operations, the exact operations can indeed be recovered.  However, not
every matrix is of that type.

-- 
#local R=<7084844682857967,0787982,826975826580>;#macro L(P)concat(#while(P)chr(
mod(P,100)),#local P=P/100;#end"")#end background{rgb 1}text{ttf L(R.x)L(R.y)0,0
translate<-.8,0,-1>}text{ttf L(R.x)L(R.z)0,0translate<-1.6,-.75,-1>}sphere{z/9e3
4/26/2001finish{reflection 1}}//ron.parker@povray.org My opinions, nobody else's


Post a reply to this message

From: Peter Popov
Subject: Re: Povray Parser for Moray
Date: 17 Oct 2001 18:42:03
Message: <mt1sst08ttke4r3ul5o3ctle7dsmf1lh4n@4ax.com>
On 17 Oct 2001 16:56:20 -0400, ron### [at] povrayorg (Ron Parker)
wrote:

>Provided you know it came from a given sequence of scale/rotate/translate
>operations, the exact operations can indeed be recovered.  However, not
>every matrix is of that type.

If there's no shearing involved, and the matrix is nonsingular, it
should do. Or is it not so? I'm just guessing here.


Peter Popov ICQ : 15002700
Personal e-mail : pet### [at] vipbg
TAG      e-mail : pet### [at] tagpovrayorg


Post a reply to this message

From: Ron Parker
Subject: Re: Povray Parser for Moray
Date: 17 Oct 2001 18:43:46
Message: <slrn9ss2d5.e8a.ron.parker@fwi.com>
On Thu, 18 Oct 2001 01:38:30 +0300, Peter Popov wrote:
>On 17 Oct 2001 16:56:20 -0400, ron### [at] povrayorg (Ron Parker)
>wrote:
>
>>Provided you know it came from a given sequence of scale/rotate/translate
>>operations, the exact operations can indeed be recovered.  However, not
>>every matrix is of that type.
>
>If there's no shearing involved, and the matrix is nonsingular, it
>should do. Or is it not so? I'm just guessing here.

It is so.  It's the shearing that's the problem.  I think even a singular
matrix can be decomposed, but I might be wrong on that.  I did all the
math a few years ago; if anyone cares, I'll see if I can find it and 
repost it.

-- 
#local R=<7084844682857967,0787982,826975826580>;#macro L(P)concat(#while(P)chr(
mod(P,100)),#local P=P/100;#end"")#end background{rgb 1}text{ttf L(R.x)L(R.y)0,0
translate<-.8,0,-1>}text{ttf L(R.x)L(R.z)0,0translate<-1.6,-.75,-1>}sphere{z/9e3
4/26/2001finish{reflection 1}}//ron.parker@povray.org My opinions, nobody else's


Post a reply to this message

From: Lutz Kretzschmar
Subject: Re: Povray Parser for Moray
Date: 17 Oct 2001 19:22:50
Message: <lf3sstsk4qui3ombgr4dat4se1d51lh449@4ax.com>
Hi Keith Hull, you recently wrote in povray.advanced-users:

> I can't change the base/cap vectors only the scale/rotate/translate vectors.
> Does anybody have any ideas? 
I have an idea :-)

Think of a vector from the middle of the base to the middle of the cap
(i.e. connecting the two given endpoints).
Transform it so that the base is in the origin (basically subtract P2
from P1).
Now figure out how to rotate it so that it's aligned along Z.
You now need to set Moray's *local* coordinate system to the
determined values. This is important, so that you can still do the
later transformations. 

In your example, it works out to setting the local coordinates to
roughly this (determined by trial and error right now :-) :
Scale     : 1, 1, 9.1  (the Z component is the length of the vector)
Rotate    : 0, -71, 35  (exercise for the reader :-)
Translate : -2, -1, 1  (this is the position of the base point)

What this does it to create a cone that has it's origin where POV-Ray
expects it, since later scales, rotations occur around the origin, not
around the base point.

The other scale, rotate, translates are derived like for every other
normal object. The best thing to do is to accumulate the
transformations in a matrix and then decompose the matrix back into
the three basic vectors. There are cases where this breaks down, you
can see the effects in IK sometimes, but generally it should work. As
Ron and Peter mentioned, if the transformations result in shearing
(rotate followed by scaling), then this cannot be handled in Moray,
but that applies to every object and has nothing to do with this
specific cone issue.

I could expose Moray's decomposition function in the plugin interface,
if you want to save yourself the coding. It's going to change for
POV-Ray 3.5 anyway :-)

Good luck.

- Lutz
  email : lut### [at] stmuccom
  Web   : http://www.stmuc.com/moray


Post a reply to this message

From: Keith Hull
Subject: Re: Povray Parser for Moray
Date: 17 Oct 2001 19:34:29
Message: <3bce1585$1@news.povray.org>
"Lutz Kretzschmar" <lut### [at] stmuccom> wrote in message
news:lf3sstsk4qui3ombgr4dat4se1d51lh449@4ax.com...
> Hi Keith Hull, you recently wrote in povray.advanced-users:
>
> > I can't change the base/cap vectors only the scale/rotate/translate
vectors.
> > Does anybody have any ideas?
> I have an idea :-)

> I could expose Moray's decomposition function in the plugin interface,
> if you want to save yourself the coding. It's going to change for
> POV-Ray 3.5 anyway :-)
>
Hi Lutz,

I would be very greatfull if you could do that, could you send me a
pre-release of the PlugIn SDK when you have time, there's no hurry as I'm
still trying to figure out what to do about #declares and textures, textures
appear to be infinately recursable :-(

Best Regards,

Keith


Post a reply to this message

From: Warp
Subject: Re: Povray Parser for Moray
Date: 18 Oct 2001 02:33:37
Message: <3bce77c1@news.povray.org>
Ron Parker <ron### [at] povrayorg> wrote:
: It is so.  It's the shearing that's the problem.

  You can achieve shearing by using a proper combination of scales and rotates.
Or is there some type of shearing which cannot be achieved with them?

  Anyways, as far as I remember, Moray doesn't support such a combination
of rotations and scales that it will shear objects although POV-Ray does...

-- 
#macro N(D,I)#if(I<6)cylinder{M()#local D[I]=div(D[I],104);M().5,2pigment{
rgb M()}}N(D,(D[I]>99?I:I+1))#end#end#macro M()<mod(D[I],13)-6,mod(div(D[I
],13),8)-3,10>#end blob{N(array[6]{11117333955,
7382340,3358,3900569407,970,4254934330},0)}//                     - Warp -


Post a reply to this message

From: Thomas Baier
Subject: Re: Povray Parser for Moray
Date: 21 Oct 2001 04:03:00
Message: <o505tt06ap9qssocur39c7726uqm6tm6co@4ax.com>
On Wed, 17 Oct 2001 17:22:46 +0100, "Keith Hull"
<kei### [at] totalisecouk> wrote:

Hi Keith,

just try this:

/*
   Decodes a 3x4 transformation matrix into separate scale, rotation,
   translation, and shear vectors. Based on a program by Spencer W.
   Thomas (Graphics Gems II) and Raw2Pov (Dan Farmer
*/
// input:	mat
// output:	scale, shear, rotate, transl
void decode_matrix (Matrix mat, Vector scale, Vector shear, Vector
rotate,
		Vector transl)
{
	unsigned int i;
	Vector row[3], temp;

	for (i = 0; i < 3; i++)
		transl[i] = mat[3][i];

	for (i = 0; i < 3; i++)
	{
		row[i][0] = mat[i][0];
		row[i][1] = mat[i][1];
		row[i][2] = mat[i][2];
	}

	scale[0] = vect_mag (row[0]);
	vect_normalize (row[0]);

	shear[0] = vect_dot (row[0], row[1]);
	row[1][0] = row[1][0] - shear[0]*row[0][0];
	row[1][1] = row[1][1] - shear[0]*row[0][1];
	row[1][2] = row[1][2] - shear[0]*row[0][2];

	scale[1] = vect_mag (row[1]);
	vect_normalize (row[1]);

	if (scale[1] != 0.0)
		shear[0] /= scale[1];

	shear[1] = vect_dot (row[0], row[2]);
	row[2][0] = row[2][0] - shear[1]*row[0][0];
	row[2][1] = row[2][1] - shear[1]*row[0][1];
	row[2][2] = row[2][2] - shear[1]*row[0][2];

	shear[2] = vect_dot (row[1], row[2]);
	row[2][0] = row[2][0] - shear[2]*row[1][0];
	row[2][1] = row[2][1] - shear[2]*row[1][1];
	row[2][2] = row[2][2] - shear[2]*row[1][2];

	scale[2] = vect_mag (row[2]);
	vect_normalize (row[2]);

	if (scale[2] != 0.0)
	{
		shear[1] /= scale[2];
		shear[2] /= scale[2];
	}

	vect_cross (temp, row[1], row[2]);
	if (vect_dot (row[0], temp) < 0.0)
	{
		for (i = 0; i < 3; i++)
		{
			scale[i]  *= -1.0;
			row[i][0] *= -1.0;
			row[i][1] *= -1.0;
			row[i][2] *= -1.0;
		}
	}

	if (row[0][2] < -1.0)
		row[0][2] = -1.0;
	if (row[0][2] > +1.0)
		row[0][2] = +1.0;


	rotate[1] = asin(-row[0][2]);
	rotate[0] = atan2 (row[1][2], row[2][2]);
	rotate[2] = atan2 (row[0][1], row[0][0]);


	/* Convert rotations to degrees */
	rotate[0] = (180.0/M_PI)*rotate[0];
	rotate[1] = (180.0/M_PI)*rotate[1];
	rotate[2] = (180.0/M_PI)*rotate[2];

	if(rotate[0] < 0.0)
		rotate[0] += 360.0;
	if(rotate[1] < 0.0)
		rotate[1] += 360.0;
	if(rotate[2] < 0.0)
		rotate[2] += 360.0;
}


>Hi All,
>
>I'm currently in the process of writing a Povray to Moray Parser, most of
>the objects can be imported and csg's, I have a few things to sort out like
>textures and declare statements. However my biggest problem is how I convert
>Povray object vectors to Moray Scale/Rotate/Translate vectors e.g. for a
>cone...
>// How do I convert from this (Pov format)......
>cone
>{
> <-2,-1,1>, 4,
> <5,-6,4>, 2
>  scale <0.5,0.5,0.5>
>  rotate <12,36,8>
>  translate  <-5,-1,1>
>}
>
>// to this (Moray format)......
>cone {
>  <0,0,0>, 4,
>  <0,0,1>, 2
>//  scale <x,y,z>
>//  rotate <x,y,z>
>//  translate  <x,y,z>
>}
>I can't change the base/cap vectors only the scale/rotate/translate vectors.
>Does anybody have any ideas? For the translate I assume I can add the base
>vector and the cone translate to get a Moray translation vector, but I'm
>stumpted on the scale and rotate vectors.
>
>Any help would be appriciated.....
>
>Many Thanks,
>
>Keith
>
>BTW is this the best place to post this....... maybe it should have gone to
>Pov programming?
>
>


Post a reply to this message

From: Keith Hull
Subject: Re: Povray Parser for Moray
Date: 22 Oct 2001 17:17:51
Message: <3bd48cff@news.povray.org>
"Thomas Baier" <NOS### [at] stmuccom> wrote in message
news:o505tt06ap9qssocur39c7726uqm6tm6co@4ax.com...
> On Wed, 17 Oct 2001 17:22:46 +0100, "Keith Hull"
> <kei### [at] totalisecouk> wrote:
>
> Hi Keith,
>
> just try this:
>
> /*
>    Decodes a 3x4 transformation matrix into separate scale, rotation,
>    translation, and shear vectors. Based on a program by Spencer W.
>    Thomas (Graphics Gems II) and Raw2Pov (Dan Farmer
> */
Hi All,

Lutz has kindly given me the relavent code and it works very well.

Thanks to everybody.

Best Regards,

Keith


Post a reply to this message

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