PDA

View Full Version : 2d Map with Lines between points, help!


Majestic12
04-16-2014, 04:54 AM
Hello everybody!

I'm a beginner in Vizard and I'm currently trying to create a visualization using a map.

Basically what I have is a 2d map and a set of points(from the map) I want to draw lines inbetween. The issue is that my points that I use for the lines are based on the texture coordinates of the map itself so that when I try to create vertices using these points they show up at the typical X, Y, Z coordinate system of Vizard instead of "on" the map.

My vision for this is to have the map and then see the lines in front of the map. Currently I have the map and then the lines elsewhere in the world.

Does anybody have any pointers / solutions for this? How would I solve this matter the best way? Is it possible?

M12

farshizzo
04-18-2014, 09:23 AM
You can use on-the-fly objects to create the points and lines then add them to a texture quad that is displaying the map. Here is an example:
import viz
viz.go()

# Points in texture coordinate system
POINTS = [ (0.1,0.2)
, (0.9,0.2)
, (0.5,0.8)
]

# Lines in texture coordinate system
LINES = [ [(0.1,0.2), (0.9,0.2)]
, [(0.1,0.2), (0.5,0.8)]
, [(0.5,0.8), (0.9,0.2)]
]


# Load map texture
texture = viz.addTexture('ball.jpg')

# Create quad to display texture
quad = viz.addTexQuad(texture=texture, pos=(0,1.5,3))
quad.zoffset(1,1)

# Create points and lines
viz.startLayer(viz.POINTS)
viz.vertexColor(viz.YELLOW)
viz.pointSize(3)
for p in POINTS:
viz.vertex(p[0]-0.5, p[1]-0.5, 0)

viz.startLayer(viz.LINES)
viz.vertexColor(viz.GREEN)
for l1,l2 in LINES:
viz.vertex(l1[0]-0.5, l1[1]-0.5, 0)
viz.vertex(l2[0]-0.5, l2[1]-0.5, 0)

# Add points/lines to quad
viz.endLayer(parent=quad)

Majestic12
04-20-2014, 10:53 PM
Hello Farshizzo,

Thank you for the example.

Regarding loading a map onto a texture, is that only possible with TexQuads? I tried to do it with a quad I made in a Layer(QUADS) and could not wrap my texture onto it (it became white), but it worked fine with TexQuad.

Here is what I tried:


viz.startLayer(viz.QUADS)
viz.vertex(0,0,0)
viz.vertex(2048,0,0)
viz.vertex(2048,0,2048)
viz.vertex(0,0,2048)
mapQuad = viz.endLayer()

texture = viz.addTexture('1.png')
mapQuad.texture = texture


You see the coordinates I have are not specified in the Vizard coordinate system(0-1) but in the resolution of the actual image. For example, the map is 2048x2048 and one of the points is 1620,1. I wanted to try making a quad with that size, putting it in the 0-2048 Vizard coordinate system, wrapping the map texture onto it and then simply displaying points and lines on the map.

Do you know if that is possible? Are TexQuads customizable in that manner?

Thank you,
M12

Majestic12
04-21-2014, 06:48 PM
Hello again,

I've tried the following too:


viz.startLayer(viz.QUADS)
viz.vertex(0,0,0)
viz.vertex(2048,0,0)
viz.vertex(2048,0,2048)
viz.vertex(0,0,2048)
mapQuad = viz.endLayer()

mapQuad.zoffset(1,1)
mapQuad.texture(viz.add('1.png'))


Using that code I get a flat purple surface. The one in my prior post had a white surface instead.

Majestic12
04-22-2014, 02:46 AM
Hey again,

Sorry for so many replies in a row. I realized that I had forgotten my texcoords in front of my vertices, I fixed it and now I can see the map image.

Thanks!
M12