POV-Ray : Newsgroups : povray.binaries.scene-files : Bouncing problem Server Time
29 Mar 2024 10:07:48 EDT (-0400)
  Bouncing problem (Message 1 to 1 of 1)  
From: "Jörg \"Yadgar\" Bleimann"
Subject: Bouncing problem
Date: 20 Aug 2015 10:20:37
Message: <55d5e235@news.povray.org>
(see my question on povray.binaries.animation)

/* POVigma - Enigma as seen from the ball! */
/* (c) 2015 by Jörg "Yadgar" Bleimann */

#declare os=0; // 0: Linux, 1: Windows 7

#declare amb=0.2;

// PIGMENTS

#declare P_Grey_Marble=
pigment
{
   marble
   color_map
   {
     [0  rgb 0.65]
     [0.4 rgb 0.65]
     [0.42 rgb 0.85]
     [0.46 rgb 0.85]
     [0.48 rgb 0.65]
     [0.73 rgb 0.65]
     [0.735 rgb 0.3]
     [0.755 rgb 0.3]
     [0.76  rgb 0.65]
     [1     rgb 0.65]
   }
   turbulence 1.5
   scale 0.2
}

#declare P_Brass=
pigment
{
   color rgb <0.7, 0.65, 0.28>
}

#declare P_Grass=
pigment
{
   bozo
   color_map
   {
     [0   rgb <0.1, 0.65, 0.1>]
     [0.3 rgb <0.13, 0.85, 0.13>]
     [0.6 rgb <0.1, 0.65, 0.1>]
     [0.7 rgb <0.4, 0.4, 0.05>]
     [0.8 rgb <0.1, 0.65, 0.1>]
     [1   rgb <0.13, 0.85, 0.13>]
   }
   turbulence 700
}

#declare P_Light_Grass=
pigment
{
   bozo
   color_map
   {
     [0   rgb <0.15, 0.8, 0.15>]
     [0.3 rgb <0.4, 1, 0.4>]
     [0.6 rgb <0.15, 0.8, 0.15>]
     [0.7 rgb <0.5, 0.5, 0>]
     [0.8 rgb <0.15, 0.8, 0.15>]
     [1   rgb <0.4, 1, 0.4>]
   }
   turbulence 700
}

#declare P_Grass_and_Light_Grass_1=
pigment
{
   object
   {
     object { sphere { 0, 1 } }
     pigment { P_Grass }
     pigment { P_Light_Grass }
   }
}

#declare P_Grass_and_Light_Grass_2=  // rotated y*90
pigment
{
   object
   {
     object { sphere { <1, 0, 0>, 1 } }
     pigment { P_Grass }
     pigment { P_Light_Grass }
   }
}

#declare P_Grass_and_Light_Grass_3=   // rotated y*180
pigment
{
   object
   {
     object { sphere { <1, 0, 1>, 1 } }
     pigment { P_Grass }
     pigment { P_Light_Grass }
   }
}

#declare P_Grass_and_Light_Grass_4=  // rotated y*270
pigment
{
   object
   {
     object { sphere { <0, 0, 1>, 1 } }
     pigment { P_Grass }
     pigment { P_Light_Grass }
   }
}

#declare P_Grass_and_Light_Grass_1_Inverted=
pigment
{
   object
   {
     object { sphere { 0, 1 } }
     pigment { P_Light_Grass }
     pigment { P_Grass }
   }
}

#declare P_Grass_and_Light_Grass_2_Inverted=  // rotated y*90
pigment
{
   object
   {
     object { sphere { <1, 0, 0>, 1 } }
     pigment { P_Light_Grass }
     pigment { P_Grass }
   }
}

#declare P_Grass_and_Light_Grass_3_Inverted=   // rotated y*180
pigment
{
   object
   {
     object { sphere { <1, 0, 1>, 1 } }
     pigment { P_Light_Grass }
     pigment { P_Grass }
   }
}

#declare P_Grass_and_Light_Grass_4_Inverted=  // rotated y*270
pigment
{
   object
   {
     object { sphere { <0, 0, 1>, 1 } }
     pigment { P_Light_Grass }
     pigment { P_Grass }
   }
}

#declare P_Blue_Oxyd=
pigment
{
   gradient y
   color_map
   {
     [0   rgb <0, 0, 0.5>]
     [0.2 rgb <0, 0, 1>]
     [0.8 rgb <0, 1, 1>]
     [1   rgb <0.5, 1, 1>]
   }
   scale <1, 2, 1>
   turbulence 0.2

}

#declare P_Blue_Oxyd_Fins=
pigment
{
   gradient z
   color_map
   {
     [0    rgbft <1, 1, 1, 0.5, 0.5>]
     [0.49 rgbft <1, 1, 1, 0.5, 0.5>]
     [0.49 rgbft <1, 1, 1, 0, 0>]
     [0.51 rgbft <1, 1, 1, 0, 0>]
     [0.51 rgbft <1, 1, 1, 0.5, 0.5>]
     [1    rgbft <1, 1, 1, 0.5, 0.5>]
   }
}

#declare P_Pulsating_Red=
pigment
{
   color rgb <1, 0.25+0.25*sin(radians(clock*18)), 
0.25+0.25*sin(radians(clock*18))>
}


// FINISHES

#declare F_Polished_Stone=
finish
{
   diffuse 1
   ambient amb
   brilliance 0.35
   phong 0.7
   phong_size 120
}

#declare F_Dull_Metal=
finish
{
   diffuse 1
   ambient amb
   brilliance 0.2
   phong 0.9
   phong_size 50
   metallic
}

#declare F_Grass=
finish
{
   diffuse 1
   ambient amb
   brilliance 0.15
}

#declare F_Incandescent =
finish
{
   ambient 1
}


// TEXTURES

#declare T_Grey_Marble=
texture
{
   pigment { P_Grey_Marble }
   finish { F_Polished_Stone }
}

#declare T_Dull_Brass=
texture
{
   pigment { P_Brass }
   finish { F_Dull_Metal }
}

#declare T_Grass=
texture
{
   pigment { P_Grass }
   finish { F_Grass }
}

#declare T_Light_Grass=
texture
{
   pigment { P_Light_Grass }
   finish { F_Grass }
}

#declare T_Grass_and_Light_Grass_1=
texture
{
   pigment { P_Grass_and_Light_Grass_1 }
   finish { F_Grass }
}

#declare T_Grass_and_Light_Grass_2=
texture
{
   pigment { P_Grass_and_Light_Grass_2 }
   finish { F_Grass }
}

#declare T_Grass_and_Light_Grass_3=
texture
{
   pigment { P_Grass_and_Light_Grass_3 }
   finish { F_Grass }
}

#declare T_Grass_and_Light_Grass_4=
texture
{
   pigment { P_Grass_and_Light_Grass_4 }
   finish { F_Grass }
}

#declare T_Grass_and_Light_Grass_1_Inverted=
texture
{
   pigment { P_Grass_and_Light_Grass_1_Inverted }
   finish { F_Grass }
}

#declare T_Grass_and_Light_Grass_2_Inverted=
texture
{
   pigment { P_Grass_and_Light_Grass_2_Inverted }
   finish { F_Grass }
}

#declare T_Grass_and_Light_Grass_3_Inverted=
texture
{
   pigment { P_Grass_and_Light_Grass_3_Inverted }
   finish { F_Grass }
}

#declare T_Grass_and_Light_Grass_4_Inverted=
texture
{
   pigment { P_Grass_and_Light_Grass_4_Inverted }
   finish { F_Grass }
}

#declare T_Blue_Oxyd_Raw=
texture
{
   pigment { P_Blue_Oxyd }
   finish { F_Dull_Metal }
}

#declare T_Blue_Oxyd_Fins_1=
texture
{
   pigment { P_Blue_Oxyd_Fins rotate <0, 45, 0> translate <0, 0, 0.29>}
   finish { F_Dull_Metal }
}

#declare T_Blue_Oxyd_Fins_2=
texture
{
   pigment { P_Blue_Oxyd_Fins rotate <0, -45, 0> translate <0, 0, 0.71> }
   finish { F_Dull_Metal }
}

#declare T_Blue_Oxyd=
texture { T_Blue_Oxyd_Raw }
texture { T_Blue_Oxyd_Fins_1 }
texture { T_Blue_Oxyd_Fins_2 }

#declare T_Dark_Glass=
texture
{
   pigment { color rgbft <0.2, 0.2, 0.2, 0.25, 0.25> }
   finish { ambient 0.5 diffuse 1 brilliance 0.5 phong 0.9 phong_size 
100 reflection 0.1 }
}

#declare T_Pulsating_Red=
texture
{
   pigment { P_Pulsating_Red }
   finish { F_Incandescent }
}

// OBJECTS

#declare Base_Cutoff=
box
{
   -0.05, <0.05, 1.1, 0.05>
   rotate <0, 45, 0>
}


#declare Base =
difference
{
   box
   {
     0, 1
   }
   object { Base_Cutoff }
   object { Base_Cutoff translate <1, 0, 0>}
   object { Base_Cutoff translate <1, 0, 1>}
   object { Base_Cutoff translate <0, 0, 1>}
}

#declare Oxyd_Base =
box
{
   0, 1
}


#declare Roof =
mesh2
{
   vertex_vectors
   {
     5,
     <0.05, 1, 0.05>, <0.05, 1, 0.95>, <0.95, 1, 0.95>, <0.95, 1, 0.05>, 
<0.5, 1.5, 0.5>
   }
   face_indices
   {
     4,
     <0, 1, 4>, <1, 2, 4>, <2, 3, 4>, <3, 0, 4>
   }
}

#declare Oxyd_Roof =
mesh2
{
   vertex_vectors
   {
     5,
     <0.015, 1, 0.015>, <0.015, 1, 0.985>, <0.985, 1, 0.985>, <0.985, 1, 
0.015>, <0.5, 1.5, 0.5>
   }
   face_indices
   {
     4,
     <0, 1, 4>, <1, 2, 4>, <2, 3, 4>, <3, 0, 4>
   }
}

/* #declare Oxyd_Roof_Fins=
mesh2
{
   vertex_vectors
   { */


#declare Border_Stone_01=
union
{
   object
   {
     Base
     texture { T_Grey_Marble }
   }
   object
   {
     Roof
     texture { T_Dull_Brass }
   }
}

#declare Blue_Oxyd_Stone=
union
{
   object
   {
     Oxyd_Base
     texture { T_Grey_Marble }
   }
   object
   {
     Oxyd_Roof
     texture { T_Blue_Oxyd }
   }
}


#declare Soil_Tile=
box
{
   <0, -0.01, 0>, <1, 0, 1>
}

#declare Ball=
sphere
{
   <0, 0.35, 0>, 0.35
   texture { T_Dark_Glass }
}

#declare InfoPoint=
union
{
   box
   {
     <-0.15, 0, -0.1>, <0.15, 0.05, 0.1>
   }
   box
   {
     <-0.1, 0.05, -0.1>, <0.1, 0.5, 0.1>
   }
   box
   {
     <0.1, 0.45, -0.1>, <0.15, 0.5, 0.1>
   }
   cylinder
   {
     <0, 0.7, -0.1>, <0, 0.7, 0.1>, 0.1
   }
   scale 0.35
   rotate <0, clock*9, 0>
   texture { T_Pulsating_Red }
}


// ACTUAL SCENE

light_source
{
   <-3000, 10000, 3000>
   color rgb 0.75
}

#declare a=0;
#while (a < 13)
   #declare b=0;
   #while (b < 20)
     #if (a > 0 & a < 12 & b > 0 & b < 19)

     #else
       object { Border_Stone_01 translate <b, 0, a> }
     #end
     #declare b=b+1;
   #end
   #declare a=a+1;
#end

object
{
   Blue_Oxyd_Stone
   translate <16, 0, 9>
}

object
{
   Blue_Oxyd_Stone
   translate <9, 0, 9>
}

object
{
   Blue_Oxyd_Stone
   translate <9, 0, 3>
}

object
{
   Blue_Oxyd_Stone
   translate <16, 0, 3>
}


#declare a=0;
#while (a < 13)
   #declare b=0;
   #while (b < 20)
     object
     {
       Soil_Tile
       #if ((a >= 2 & a <= 10 & b >= 9 & b <= 16) | (a >= 3 & a <= 9 & b 
= 8) | (a >= 3 & a <= 9 & b = 17) | (a = 6 & b >= 5 & b <= 7) | (a >= 5 
& a <= 7 & b >= 2 & b <= 4) | ((a = 4 | a = 8) & b = 3 ))
         texture { T_Light_Grass }
       #else
         #if ( a = 10 & b = 17 | (a = 8 & b = 4))
           texture { T_Grass_and_Light_Grass_1 }
         #else
           #if (a = 10 & b = 8 | (a = 8 & b = 2))
             texture { T_Grass_and_Light_Grass_2 }
           #else
             #if (a = 2 & b = 8 | (a = 4 & b = 2))
               texture { T_Grass_and_Light_Grass_3 }
             #else
               #if (a = 2 & b = 17 | (a = 4 & b = 4))
                 texture { T_Grass_and_Light_Grass_4 }
               #else
                 #if (a = 5 & b = 7)
                   texture { T_Grass_and_Light_Grass_1_Inverted }
                 #else
                   #if (a = 5 & b = 5)
                     texture { T_Grass_and_Light_Grass_2_Inverted }
                   #else
                     #if (a = 7 & b = 5)
                      texture { T_Grass_and_Light_Grass_3_Inverted }
                     #else
                       #if (a = 7 & b = 7)
                        texture { T_Grass_and_Light_Grass_4_Inverted }
                       #else
                         texture { T_Grass }
                       #end
                     #end
                   #end
                 #end
               #end
             #end
           #end
         #end
       #end
       translate <b, 0, a>
     }
     #declare b=b+1;
   #end
   #declare a=a+1;
#end

object
{
   InfoPoint
   translate <3.5, 0.1, 7.5>
}

object
{
   InfoPoint
   translate <3.5, 0.1, 5.5>
}

#declare ballpos_start = <3.5, 0, 6.5>;
#declare ballpos = ballpos_start;
#declare ball_speed = 0.1;
#declare azi_start=0;
#declare dir_start=60;
#declare hit=0; // flag for collision with walls or Oxyd stones
#if (clock = 0)
   #declare azi = azi_start;
   #declare dir = dir_start;
   #declare clock_mem = clock;
   #fopen course "course.txt" write
   #write (course azi,",",dir,",",ballpos_start,",",clock_mem)
   #fclose course
#else
   #fopen course "course.txt" read
   #read (course azi,dir,ballpos_start,clock_mem)
   #fclose course
#end

#declare ballpos_next = ballpos_start + (clock-clock_mem+1) * ball_speed 
* <sin(radians(dir))*cos(radians(azi)), sin(radians(azi)), 
cos(radians(dir))*cos(radians(azi))>;
#declare ballpos_2ndnext = ballpos_start + (clock-clock_mem+2) * 
ball_speed * <sin(radians(dir))*cos(radians(azi)), sin(radians(azi)), 
cos(radians(dir))*cos(radians(azi))>;

#if (ballpos_2ndnext.z > 11.65
      | ballpos_2ndnext.z < 1.35
      )
   #declare dir = 180-dir;
   #declare hit=1;
#else
   #if (ballpos_2ndnext.x > 18.65
        | (ballpos_2ndnext.x > 8.65 & ballpos_2ndnext.x < 10.35 & 
ballpos.x < 8.65 & ballpos_2ndnext.z >= 9 & ballpos_2ndnext.z <= 10)
        | ballpos_2ndnext.x < 1.35
        | (ballpos_2ndnext.x > 8.65 & ballpos_2ndnext.x < 10.35 & 
ballpos.x > 10.35 & ballpos_2ndnext.z >= 9 & ballpos_2ndnext.z <= 10)
       )
     #declare dir = 360-dir;
     #declare hit=1;
   #end
#end

#if (hit)
   #declare ballpos_start = ballpos_next;
   #declare clock_mem = clock;
   #fopen course "course.txt" write
   #write (course azi,",",dir,",",ballpos_start,",",clock_mem)
   #fclose course
#end


#declare ballpos = ballpos_start + (clock-clock_mem) * ball_speed * 
<sin(radians(dir))*cos(radians(azi)), sin(radians(azi)), 
cos(radians(dir))*cos(radians(azi))>;
#declare campos = ballpos + <0, 0.35, 0> + 
0.36*<sin(radians(dir))*cos(radians(azi)), sin(radians(azi)), 
cos(radians(dir))*cos(radians(azi))>;
// #declare campos = ballpos + <0.36, 0.35, 0>;

#warning concat("ballpos_start = ", vstr(3, ballpos_start, ",", 1, 2))
#warning concat("ballpos = ", vstr(3, ballpos, ",", 1, 2))
#warning concat("dir = ", str(dir, 1, 2))
#warning concat("clock_mem =", str(clock_mem, 1, 0))
#warning concat("ballpos_next = ", vstr(3, ballpos_next, ",", 1, 2))
#warning concat("hit = ", str(hit, 1, 0))

object
{
   Ball
   translate ballpos
}

#declare ballview=0;


camera
{
   #if (ballview)
     location campos
     look_at campos+<sin(radians(dir))*cos(radians(azi)), 
sin(radians(azi)), cos(radians(dir))*cos(radians(azi))>
     angle 80
   #else
     location <10, 30, 6.5>
     look_at <10, 0, 6.5>
     angle 40
   #end
}


Post a reply to this message

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