class ColorCube : Cube { Vector3 Color = new Vector3(1, 1, 1); public ColorCube(Vector3 color) : base() { Color = color; } public override Vector3[] GetColorData() { return new Vector3[] { Color, Color, Color, Color, Color, Color, Color, Color }; } }
The code is pretty simple, just set a color and return it for all the vertices' color (isn't OOP convenient?).
And if you want to draw a bunch of them in random positions, this will do it (keep in mind some of them might be placed out of view until we get a camera working):
Random rand = new Random(); for (int i = 0; i < 100; i++) { ColorCube c = new ColorCube(new Vector3((float)rand.NextDouble(),(float)rand.NextDouble(),(float)rand.NextDouble())); c.Position = new Vector3((float)rand.Next(-4, 4), (float)rand.Next(-4, 4), (float)rand.Next(-8, 8)); c.Rotation = new Vector3((float)rand.Next(0, 6), (float)rand.Next(0, 6), (float)rand.Next(0, 6)); c.Scale = Vector3.One * ((float)rand.NextDouble() + 0.2f); objects.Add(c); }
Hi, I'm new to OpenGL. I saw these tutorials and they look extremely useful. I was wondering if there is a chance you can do a texture to quad tutorial. I for one, don't wan't to get bogged down with too much 3d math and so on, so it would be interesting to see how we can create a simple class to allow rendering to quads, so we can use opentk to do 2d renders, like in a platformer game. I think it would be very, very helpful to alot of vb .net users. Any chance for this?
ReplyDeleteThanks for the feedback! I have a plan for upcoming tutorials right now (the current plan is to make one for a basic camera next, as soon as work lets up a bit), but I'll definitely do the textures one as soon as I can after that. A textured quad class should be really simple to add as an addendum at that point.
DeleteCool, cool, thanks - I'll keep checking back. I'm starting to get OpenTK up and running.
DeleteHi there. I been following this tutorial series and it's been a huge help to me, so Thank you. Now, I found something pretty odd while adding the ColorCube do the program. If I draw only 2 cubes, 1 being the Cube, and the other being ColorCube, one of the cubes get colored wrongly. Like only half of it's color data is from Cube, and the other half is from ColorCube. IF the amount of cubes is 3, the problem disappears.
ReplyDeleteI don't know if this has been found and solved already, but I can't find the reason why this is happening.
Hey,
DeleteI have a simmelar issue. All my Volumes have the same color. If I add the ColorCube fisr, all my other bubes have the same color as the first cube. I'll let you know if I find something.