|
From: Bruce S. <bas...@nc...> - 2010-06-18 04:06:38
|
Here is an example which seems to do what you want:
from __future__ import division
from visual import *
scene.background = color.white
scene.forward = (1,-1,-1)
road = frame(pos=(-30,0,0))
yroad = 0.05
width = 1
length = 2000
box(frame=road, pos=(length/2,-yroad/2,0), size=(length,yroad,width),
color=color.green)
for x in range(0,length,10):
curve(frame=road, pos=[(x,0.01,-width/2), (x,0.01,width/2)],
color=color.black)
truck = frame()
L = 1.7
body = box(frame=truck, pos=(L/2,0.4,0), size=(1.7,0.3,0.6),
color=color.red)
cab = box(frame=truck, pos=(L/2+.3,0.7,0), size=(.4,0.3,0.6),
color=color.red)
R = 0.17
for x in (1.1*R,L-1.2*R):
for z in (-0.25,0.15):
cylinder(frame=truck, pos=(x,R,z), radius=R, axis=(0,0,0.1),
color=color.black)
scene.range = 25
scene.center = (truck.x,0,0)
scene.mouse.getclick()
while truck.x < length-5:
rate(50)
truck.x += 0.3
scene.center = (truck.x,0,0)
However, depending on the details I can see rendering problems. For example,
if I set scene.range = 5 or 10, pieces of the scene are truncated. It
appears that there are problems in the setting of near and far clipping
planes for the 3D display when one sets the range very small for a situation
where the scene is actually very large.
Oddly, if I don't set scene.range but simply zoom in before clicking to
start the motion, I don't have the rendering problem.
In general, you probably have to generate scenery around the truck as you
go. For example, in my code instead of moving the truck in the +x direction
you could move the road in the -x direction. Then if you use short road
segments and move them to the front whenever one goes off the screen to the
back, you could keep the whole scene small.
As for problems with textures, that almost certainly indicates that you need
to update the graphic drivers. From the Linux download page at vpython.org:
Materials such as wood will work with graphics cards that support Pixel
Shader 3.0 ("PS 3.0"). See
http://en.wikipedia.org/wiki/Pixel_shader#Hardware. *Some* materials may
work with graphics cards that support PS 2.0, but other materials may need
to be manually disabled; see instructions in the *site-settings.py* module
in the Visual package in your site-packages folder. If the graphics hardware
does not support pixel shaders, the material property is ignored. If you
think you should be able to use materials but have trouble with their
display or performance, we highly recommend upgrading your video card
drivers to the latest version.
Bruce Sherwood
On Thu, Jun 17, 2010 at 5:19 PM, Baozhi Chen <bc...@gm...> wrote:
> Hi all,
>
> I am a new user of VPython. My goal is to make a 3D visualization of a
> moving autonomous vehicle for a demo. The vehicle will move along a
> long trajectory.
> For example, the whole trajectory is from 0 m to 2000 m in x-axis
> while the vehicle is only 1 or 2 m long.
> Therefore it won't look good to view the whole trajectory. I want to
> set the viewing region dynamically to an appropriate size (for
> example, from 1950 m to 2000 m in x-axis) so
> that the vehicle does not look too small. I have tried to use the
> scene.center and scene.range to change the view region but it doesn't
> seem to work.
> Could any one tell me what's wrong and how to set the view region?
>
> I am using a SONY VGN-CR490 laptop with intel 965GM graphics driver.
> My OS is Ubuntu 10.04 and VPython is the latest version 5.32 (I
> followed INSTALL.txt to install).
> BTW, there seems to be a problem when I tried to use the textures,
> which leads to the crash of the GNOME window system.
> Some 3D text object cannot be displayed in my visualization although
> the text examples coming with Vpython work.
>
> Thanks.
>
> Bob
>
>
|