|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
I have a #macro that creates a wall :
#macro OutSideWall(Position1,End1,Position2,End2)
// ---------- for testing purpose only
cylinder{Position1,Position1+<0,400,0>,30 pigment { red 1 }}
cylinder{Position2,Position2+<0,450,0>,25 pigment { blue 1 }}
// ----------
#local XLength = Position2.x - Position1.x;
#local ZLength = Position2.z - Position1.z;
#local WallLength = VDist(Position1,Position2);
#local Angle = degrees(asin(ZLength/WallLength));
#local LogCounter = 0;
#declare ThisWall =
union {
#while ((LogCounter * HtHLogDistance) < OutsideWallHeight)
object { Log(WallLength,End1,End2) translate y * HtHLogDistance *
(LogCounter+0.5) }
#local LogCounter = LogCounter + 1;
#end
}
object { ThisWall rotate y * Angle translate Position1 }
#end
so I can do this
OutSideWall(< 200,0,1200>, true,< 200,0,800>, true)
OutSideWall(< 200,0,800>, true,< 400,0, 800>, true)
for a whole building
The walls are created just fine and placed at the correct place (Position1)
but the rotation (rotate Angle) is wrong.
I know this is stupidly simple, but I guess I'm dumber :)
--
Ger
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
> The walls are created just fine and placed at the correct place
> (Position1)
> but the rotation (rotate Angle) is wrong.
rotate moves an object around the origin,
from your code
OutSideWall(< 200,0,1200>, true,< 200,0,800>, true)
I deduce that you have a wall starting at <200,0,1200>
(Position1) and going to <200,0,800> (Position2)
So if you wish to rotate the wall around Position1 you'd
first translate the wall to the origin, then rotate it, then
put it back at Position1.
object {
ThisWall
translate -Position1
rotate y * Angle
translate Position1
}
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Tim Attwood wrote:
>> The walls are created just fine and placed at the correct place
>> (Position1)
>> but the rotation (rotate Angle) is wrong.
>
> rotate moves an object around the origin,
>
> from your code
> OutSideWall(< 200,0,1200>, true,< 200,0,800>, true)
> I deduce that you have a wall starting at <200,0,1200>
> (Position1) and going to <200,0,800> (Position2)
>
> So if you wish to rotate the wall around Position1 you'd
> first translate the wall to the origin, then rotate it, then
> put it back at Position1.
>
> object {
> ThisWall
> translate -Position1
> rotate y * Angle
> translate Position1
> }
The wall is created at the origin, then rotated and then translated.
Everything works okay except for the rotation angle.
--
Ger
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Ger <No.### [at] ThankYou> wrote:
> The wall is created at the origin, then rotated and then translated.
> Everything works okay except for the rotation angle.
I see two problems. Firstly, I think you should be using arc-tan, not
arc-sin (tan(a) = opposite/adjacent). Secondly, as you look along an axis,
negative rotation is clockwise, so I would use rotate -Angle*y.
If your wall is aligned on the z-axis, you will get a division by zero
error, which will need to be trapped. You will also need to modify this
technique if position2 is in the 2nd, 3rd or 4th quadrants relative to
Hope that helps
B
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Ger wrote:
> I have a #macro that creates a wall :
>
>
> #macro OutSideWall(Position1,End1,Position2,End2)
> // ---------- for testing purpose only
> cylinder{Position1,Position1+<0,400,0>,30 pigment { red 1 }}
> cylinder{Position2,Position2+<0,450,0>,25 pigment { blue 1 }}
> // ----------
> #local XLength = Position2.x - Position1.x;
> #local ZLength = Position2.z - Position1.z;
> #local WallLength = VDist(Position1,Position2);
> #local Angle = degrees(asin(ZLength/WallLength));
>
> #local LogCounter = 0;
> #declare ThisWall =
> union {
> #while ((LogCounter * HtHLogDistance) < OutsideWallHeight)
> object { Log(WallLength,End1,End2) translate y * HtHLogDistance *
> (LogCounter+0.5) }
> #local LogCounter = LogCounter + 1;
> #end
> }
>
> object { ThisWall rotate y * Angle translate Position1 }
> #end
>
> so I can do this
>
> OutSideWall(< 200,0,1200>, true,< 200,0,800>, true)
> OutSideWall(< 200,0,800>, true,< 400,0, 800>, true)
>
> for a whole building
>
> The walls are created just fine and placed at the correct place (Position1)
> but the rotation (rotate Angle) is wrong.
You really don't need to do this arcsin and rotation stuff.
The better way to do it is:
#local vZ=vnormalize(Position2-Position1);
#local vX=vnormalize(vcross(y,vZ));
and replace the rotate and translate with this:
matrix < vX.x, vX.y, vX.z,
0, 1, 0,
vZ.x, vZ.y, vZ.z,
Position1.x, Position1.y, Position1.z>
It may help you with this to also read
http://www.geocities.com/evilsnack/matrix.htm ,
which is tutorial I wrote about the matrix transform.
Regards,
John
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
John VanSickle wrote:
>
> You really don't need to do this arcsin and rotation stuff.
>
> The better way to do it is:
>
> #local vZ=vnormalize(Position2-Position1);
> #local vX=vnormalize(vcross(y,vZ));
>
> and replace the rotate and translate with this:
>
> matrix < vX.x, vX.y, vX.z,
> 0, 1, 0,
> vZ.x, vZ.y, vZ.z,
> Position1.x, Position1.y, Position1.z>
>
> It may help you with this to also read
>
> http://www.geocities.com/evilsnack/matrix.htm ,
>
> which is tutorial I wrote about the matrix transform.
>
> Regards,
> John
I had it figured out with a lot of #if's in it, but I tried your solution
anyway because it looks so much more elegant.
But now a wall is rotated y * 90 from where it is supposed to be.
--
Ger
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Ger wrote:
> John VanSickle wrote:
>
>
>>You really don't need to do this arcsin and rotation stuff.
>>
>>The better way to do it is:
>>
>>#local vZ=vnormalize(Position2-Position1);
>>#local vX=vnormalize(vcross(y,vZ));
>>
>>and replace the rotate and translate with this:
>>
>>matrix < vX.x, vX.y, vX.z,
>> 0, 1, 0,
>> vZ.x, vZ.y, vZ.z,
>> Position1.x, Position1.y, Position1.z>
>>
>>It may help you with this to also read
>>
>> http://www.geocities.com/evilsnack/matrix.htm ,
>>
>>which is tutorial I wrote about the matrix transform.
>>
>>Regards,
>>John
>
>
> I had it figured out with a lot of #if's in it, but I tried your solution
> anyway because it looks so much more elegant.
> But now a wall is rotated y * 90 from where it is supposed to be.
If the wall is built along the x axis prior to is positioning, then use
this code to calculate vX and vZ:
#local vX=vnormalize(Position2-Position1);
#local vZ=vnormalize(vcross(vX,y));
The matrix remains the same.
Regards,
John
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
|
|