我是JSL編程和Opengl的新手,並且想知道隱藏對象。如果我最初在場景中有多個球體,我希望用戶能夠使用滑塊指定場景中的球體數量,並相應地更新它。有沒有辦法隱藏或刪除對象?
顯示列表沒有自己的任何邏輯(用於隱藏/顯示);您需要重建顯示列表以顯示您想要的內容。
sphere = Scene Display List();
sphere << sphere( .15, 15, 15 );
spheres = Scene Display List();
makespheres = Function( {n},
spheres << clear;
For( i = 1, i < n, i++,
spheres << color( i / n, 1 - i / n, .9 ); // .1,.1,.1 = almost black .9,.9,.9 = almost white
spheres << pushmatrix;
spheres << translate( (i - (n / 2)) / 3, 0, 0 );
spheres << calllist( sphere );
spheres << popmatrix;
);
);
Scene = Scene Box( 600, 600 );
Scene << backgroundcolor( 0 ); // black=0, gray=1, white=2
Scene << showarcball( always );
nspheres = 14;
makespheres( nspheres );
New Window( "x",
Scene,
Slider Box(
1,
20,
nspheres,
makespheres( nspheres );
scene << update;
)
);
Scene << perspective( 45, .2, 20 );
Scene << Translate( 0.0, 0.0, -4.5 );
Scene << arcball( spheres, 1.5 );
Scene << update;
滑塊控制球體的數量
這使用了幾層被調用的顯示列表。最小的列表“球體”只包含一個球體,但可能包含一個更複雜的物體。“spheres”列表是滑塊移動時重建的列表;保持它盡可能簡單,因此當滑塊移動時,JSL循環不必比所需更加努力。反過來,“球體”從主顯示列表中調用(通過弧形球)。另一件需要注意的事情是:被叫列表不會將被轉換(等)保持在被叫列表的本地。如果被調用列表轉換對象並且未撤消該轉換,則在完成被調用列表時,轉換仍然有效。這就是使用pushmatrix和popmatrix的原因。