How do I render a grid? (was: Please help about this problem)

@steelswing Just figure out the x,y coordinates for the center of each of your parallelograms. You can then use those coordinates to draw other sprites at those positions. Draw the background Sprite first, then your other sprites in the order you want them shown. The x,y values should be just offsets from each other by the same value. x+x+some xvalue. y+y+some yvalue.

@Bri_G yes, you can use addRect to create planes in 3D implementations. You can access the vertices the same as with other meshes (6 per rect)

Hi @yojimbo2000,

Have you ever used this? Or do you always build up your vertices systematically?

If you have used it could you post a little code to demonstrate, I’m sure I’m not the only one interested in this.

Thanks,

Bri_G
:slight_smile:

@Bri_G In response to your question above to me, you can use the mesh buffer statement to access and modify the vertices after they’ve been created. There are different options that let you modify different things for the mesh.

@Bri_G Using addRect, you can only specify x,y,w,h for 2D coordinates. But if you use the mesh buffer statement, you can modify the z coordinate which is 0 when the rect is first created. I think if you want to create 3D objects, it’s a lot easier to calculate and set the 3 vertices of a triangle than using the addRect statement and then trying to modify its vertices.

Hi @dave1707 ,

Thanks for that, don’t want to get into the buffer yet, but looks interesting. I’m sticking with building up 3D meshes for now. Thought it would be possible but doesn’t offer me much at the moment. Thanks again.

Bri_G
:slight_smile:

yeah @dave1707 is right that z is set to 0 whenever you use addRect or setRect. If you’re doing a “tabletop” environment with Z-up orientation, they’re useful for a quick and easy floor plane.

@Bri_G You could use addRect to create other than flat planes, but there’s a lot of changes to make to set the correct x,y coordinates plus rotations and translates. It would be a lot easier using vertices for triangles. Change the rotation axis ( ax,at,az) and the angle for different views.

function setup()
    displayMode(STANDARD)  
    parameter.integer("angle",-180,180,45)
    parameter.integer("ax",0,1,1)
    parameter.integer("ay",0,1,0)
    parameter.integer("az",0,1,0)
    
    m1=mesh()
    m1:addRect(-25,0,50,100)
    m1:setColors(255,0,0,255) 
    
    m2=mesh()
    m2:addRect(25,0,50,100)
    m2:setColors(255,255,0,255)  
     
    m3=mesh()
    m3:addRect(67,0,50,100)
    m3:setColors(255,0,255,255)           
end

function draw()  
    background(0)
    
    perspective(90)
    camera(0,0,-300,0,0,0,0,1,0) 
    rotate(angle,ax,ay,az)
    
    pushMatrix()
    m1:draw() 
    popMatrix() 
    
    pushMatrix()
    rotate(30,0,1,0)
    m2:draw()  
    popMatrix()
    
    pushMatrix()
    rotate(-10,0,1,0)
    translate(-4,0,-32)
    m3:draw()
    popMatrix()
end