[QUOTE=swift and shift;37453168]why are all the members references wtf[/QUOTE]
It's a reference for the base class' data. But this is a pretty horrible way to do it.
Something that disturb me is that a vector in mathematics ofter refer to a linear algebra vector that have nothing to do with color as far as I know.
[QUOTE=qqqqqqqq;37453296]It's a reference for the base class' data. But this is a pretty horrible way to do it.[/QUOTE]
Well then, what's a better way to do it?
[editline]29th August 2012[/editline]
[QUOTE=AlienCat;37454216]Something that disturb me is that a vector in mathematics ofter refer to a linear algebra vector that have nothing to do with color as far as I know.[/QUOTE]
The base operations are needed on color ocasionally, so this is a way to inherit them.
[QUOTE=AlienCat;37454216]Something that disturb me is that a vector in mathematics ofter refer to a linear algebra vector that have nothing to do with color as far as I know.[/QUOTE]
I think you're conflating linear algebra with analytical geometry. A mathematical vector/matrix can be used in myriad ways.
[QUOTE=WeltEnSTurm;37454402]Well then, what's a better way to do it?[/QUOTE]
The better way is to avoid random access to vector elements as far as possible since it's generally not a good idea, especially when exposing SIMD. But for that kind of access just stick with xyzw it's simple and obvious. If you really want to access via different letters use an inline function, at least then you're not increasing the size of your vector by 100%-200% (assuming float payload and that your compiler implements references with a native pointer which seems to be the general case).
[editline]30th August 2012[/editline]
It's also worth noting that as well as the size overhead passing by reference means any of the operands could potentially alias each other and hence the compiler is likely to generate redundant loads and stores which will hurt performance.
[QUOTE=Richy19;37446041]
Any chance you could github/pastebin the code for the actual algorithm?
[/QUOTE]
Well, the code is currently something I would be deeply ashamed of if anyone else were to see it, but the algorithm is really, really simple so you should be able to implement it yourself. Although I'm probably going to make it better with non-deprecated OpenGL and shaders and clouds and trees and other stuff, so I might upload it after that.
If I want to update the VBO each frame, what is the best way to do so?
Currently I update the list and then upload it with BufferData:
[csharp]
public override void Draw ()
{
mShader.Bind ();
// Think of way to get MVP
GL.UniformMatrix4 (mShader.GetUniform ("MVP"), false, ref mMVP);
mPositionBuffer.Bind (3);
mPositionBuffer.AddData (mPositionsList.ToArray (), sizeof(float), BufferTarget.ArrayBuffer, BufferUsageHint.StreamDraw);
mColorBuffer.Bind (3);
mColorBuffer.AddData (mColorList.ToArray (), sizeof(float), BufferTarget.ArrayBuffer, BufferUsageHint.StreamDraw);
GL.DrawArrays (BeginMode.Lines, 0, mAmountVerticies);
mColorBuffer.Unbind ();
mPositionBuffer.Unbind ();
Shader.Unbind ();
mPositionsList.Clear ();
mColorList.Clear ();
mAmountVerticies = 0;
}[/csharp]
[QUOTE=Richy19;37455381]If I want to update the VBO each frame, what is the best way to do so?
Currently I update the list and then upload it with BufferData:
-codesnip-
[/QUOTE]
If the size of the VBO isn't changing you can use GL.BufferSubData, which prevents deletion and re-allocation of the buffer.
[editline]29th August 2012[/editline]
Also some content. I implemented holes in the terrain. Any vertex with value NaN will be skipped over by both the graphics buffer generator and the physics body generator.
At first the vertex normals of the surrounding vertices were pitch black because they took into account the NaN value, so I added a check for it and set the height value as the vertex's current height instead, which created this really cool emboss type of effect. I might keep it or make it so that all sides darken a bit.
[img_thumb]http://i.imgur.com/fMgP2.jpg[/img_thumb]
Started to play around with OOGL, added a simple shadowmap filter which I'm almost 100% sure looks wrong (it uses 16 tap poisson disc) and a spotlight cookie texture. Also added some controls like zooming in, changing shadowmap filter and shadow bias. The base code is from Overv's shadowmapping demo but I changed the model (I had to reexport it smaller from 3ds max too.)
[img]http://puu.sh/10081[/img]
filter comparison:
[img]http://puu.sh/100eq[/img]
[img]http://puu.sh/100eD[/img]
Bias increased:
[img]http://puu.sh/100eI[/img]
I'm probably gonna look up how to do proper spotlight attenuation next.
[QUOTE=WeltEnSTurm;37453164]Probably late for vector discussion, but I made a vector class in C++ which allows simple maths and can be used as base for like, a color class.
[cpp]
class color: public math::vector<4> {
public:
float& r;
float& g;
float& b;
float& a;
color(float r = 1, float g = 1, float b = 1, float a = 1):
r(data[0]), g(data[1]), b(data[2]), a(data[3])
{
this->r = r; this->g = g; this->b = b; this->a = a;
}
color(const vector& c):
color(c.data[0], c.data[1], c.data[2], c.data[3])
{}
color& operator = (const color& c){
r = c.r; g = c.g; b = c.g; a = c.a;
return *this;
}
};
int main(){
color whatever = color(0.1, 0, 1, 0.7);
color whatever2 = whatever;
color mul = color(1, 1, 1, 0.5);
std::cout << mul * whatever2 << std::endl; // I guess we have that too
return 0;
}
[/cpp][/QUOTE]
That's actually pretty clever, though I probably wouldn't treat my colors the same as vectors. It doesn't make much sense to have a dot product in your colors, for example (though you don't appear to have one, you might eventually). If it were me, I would have an entirely separate class for colors.
If you're doing this for passing colors and vectors into the same function, for example:
[cpp]void doStuff(math::vector<4> yada)[/cpp]
It would probably make more sense to accept a float* (and have a operator float* or operator[]) or overload the method to accept a color [b]or[/b] a vector4.
-snip-
[b]Edit:[/b] [url=https://dl.dropbox.com/u/11093974/Junk/codz.png]Is this happening to anyone else?[/url]
[QUOTE=jalb;37456308]That's actually pretty clever, though I probably wouldn't treat my colors the same as vectors. It doesn't make much sense to have a dot product in your colors, for example (though you don't appear to have one, you might eventually). If it were me, I would have an entirely separate class for colors.
If you're doing this for passing colors and vectors into the same function, for example:
void doStuff(math::vector<4> yada)
It would probably make more sense to accept a float* (and have a operator float* or operator[]) or overload the method to accept a color [B]or[/B] a vector4.
Also, something to be careful of with the templates: Your code isn't very portable. This line in particular:
template<size_t length = 3, class type = float>
Uses default arguments for templates. This was introduced in C++11 and some modern compilers (including Visual Studio 2010's compiler) don't support this yet. Personally I say fuck the outdated compilers and keep moving ahead, but this is a heads up in case you (or anyone else) were unaware.
[B]Edit:[/B] [URL="https://dl.dropbox.com/u/11093974/Junk/codz.png"]Is this happening to anyone else?[/URL][/QUOTE]
I'll think about separation as soon as I implement stuff that isn't needed by color, but I doubt it will affect performance in any way except a slightly bigger executable.
And I'm not doing this to pass colors and vectors to the same function, but because I'm lazy (or try to be efficient, whatever) and don't want to write the same code twice.
I've gotten used to C++11, and as long as people don't pay me to switch compilers I'll stay with GCC 4.7.
And yes, code view is fucked up. I like how line number digits get a newline.
[QUOTE=Legend286;37456132]Started to play around with OOGL, added a simple shadowmap filter which I'm almost 100% sure looks wrong (it uses 16 tap poisson disc) and a spotlight cookie texture. Also added some controls like zooming in, changing shadowmap filter and shadow bias. The base code is from Overv's shadowmapping demo but I changed the model (I had to reexport it smaller from 3ds max too.)
[img]http://puu.sh/10081[/img]
filter comparison:
[img]http://puu.sh/100eq[/img]
[img]http://puu.sh/100eD[/img]
Bias increased:
[img]http://puu.sh/100eI[/img]
I'm probably gonna look up how to do proper spotlight attenuation next.[/QUOTE]
Natural light attenuation = 1/(d^2)
[QUOTE=nVidia;37456404]Natural light attenuation = 1/(d^2)[/QUOTE]
I know that, but for spotlights you have to calculate it based on inner and outer cone (unless you want it to look like shit.)
Anyway, here's a video:
[hd]http://www.youtube.com/watch?v=QD435Hbc3Po[/hd]
Aaand ermahgerd using spotlight cookie as attenuation like a lazy fuck.
[img]http://puu.sh/1019a[/img]
We've all done the "send HTTP GET requests to random IPs" thing.
I wrote one that sends 0xFE to random IPs on port 25565, in the hope that I might find some minecraft servers. ([URL="http://mc.kev009.com/Protocol#0xFE"]Explanation[/URL])
[IMG]http://i.imgur.com/BXxe5.png[/IMG]
I ran it overnight and woke up to 30 successful hits on the log.
So I was actually working on my planet generator, trying to make decent geospheres, but I got distracted again while I was making a Processing sketch about subdividing triangles...
[vid]https://dl.dropbox.com/u/4081391/nice-.webmvp8.webm[/vid]
Wobbly version:
[vid]https://dl.dropbox.com/u/4081391/niceTOO-.webmvp8.webm[/vid]
Also, if you keep this thing running with a shitload of subdivisions and tiny lines, it starts making art:
[img]http://i.imgur.com/YxNDn.png[/img]
[img]http://i.imgur.com/yjgHe.png[/img]
[QUOTE=Dlaor-guy;37456888]So I was actually working on my planet generator, trying to make decent geospheres, but I got distracted again while I was making a Processing sketch about subdividing triangles...
[vid]https://dl.dropbox.com/u/4081391/nice-.webmvp8.webm[/vid]
Wobbly version:
[vid]https://dl.dropbox.com/u/4081391/niceTOO-.webmvp8.webm[/vid]
Also, if you keep this thing running with a shitload of subdivisions and tiny lines, it starts making art:
[img]http://i.imgur.com/YxNDn.png[/img]
[img]http://i.imgur.com/yjgHe.png[/img][/QUOTE]
Holy shit. I also love how the first looks exactly like dx11 tessellated geometry.
Oh and the last one looks like wrinkled cloth! So cool.
Woops, page king, I don't have anything to show but i got my audio visualizer running perfectly on my android phone (Galaxy S2).
[QUOTE=Dlaor-guy;37455026]Well, the code is currently something I would be deeply ashamed of if anyone else were to see it, but the algorithm is really, really simple so you should be able to implement it yourself. Although I'm probably going to make it better with non-deprecated OpenGL and shaders and clouds and trees and other stuff, so I might upload it after that.[/QUOTE]
So is the algorithm basically, Create a sphere made of triangles
create a plane, give it random X,Y,Z rotation
check points infront of plane, and scale smaller, points behind scale bigger
draw and repeat?
[QUOTE=Richy19;37457462]So is the algorithm basically, Create a sphere made of triangles
create a plane, give it random X,Y,Z rotation
check points infront of plane, and scale smaller, points behind scale bigger
draw and repeat?[/QUOTE]
Generate a random unit vector by making generating 3 Gaussian-distribution numbers, then normalizing. Check each vertex against the vector simply with a dot-product. If the dot product is positive, scale by some amount. If it's negative, scale by the reciprocal of that amount.
That's how I would do it, anyway. Fast and easy.
[QUOTE=Smashmaster;37457562]Generate a random unit vector by making generating 3 Gaussian-distribution numbers, then normalizing. Check each vertex against the vector simply with a dot-product. If the dot product is positive, scale by some amount. If it's negative, scale by the reciprocal of that amount.
That's how I would do it, anyway. Fast and easy.[/QUOTE]
You don't even need to normalize the vector, you're just going by the sign of the result anyway.
Made a text input field because why not:
[vid]https://dl.dropbox.com/u/41041550/Coding/C%23/Forgotten%20Voxels%20Mono/Text%20field.webm[/vid]
Why is "Connect" a guitar?
[QUOTE=voodooattack;37458540]Why is "Connect" a guitar?[/QUOTE]
Sitting 'round a campfire, playing "Sweet Home Alabama" and connecting with people.
[QUOTE=voodooattack;37458540]Why is "Connect" a guitar?[/QUOTE]
It actually just plays a song called "Connect" instead of connecting?
[QUOTE=Richy19;37457462]So is the algorithm basically, Create a sphere made of triangles
create a plane, give it random X,Y,Z rotation
check points infront of plane, and scale smaller, points behind scale bigger
draw and repeat?[/QUOTE]
[cpp]typedef struct
{
float x, y, z;
} vec3;
vec3 random_vec3()
{
vec3 v;
do
{
v.x = 2.0f * randf() - 1.0f;
v.y = 2.0f * randf() - 1.0f;
v.z = 2.0f * randf() - 1.0f;
} while (v.x * v.x + v.y * v.y + v.z * v.z > 1);
return v;
}
void generate_planes(vec3 *plane_v, int plane_c)
{
int i;
for (i = 0; i < plane_c; i++)
random_vec3(&plane_v[i]);
}
float vtx_plane_dot(vec3 vtx, vec3 plane)
{
return plane.x * (vtx.x - plane.x) +
plane.y * (vtx.y - plane.y) +
plane.z * (vtx.z - plane.z);
}
int vtx_get_offset(vec3 vtx, vec3 *plane_v, int plane_c)
{
int i;
int res = 0;
for (i = 0; i < plane_c; i++)
{
float f = vtx_plane_dot(vtx, plane_v[i]);
if (f > 0)
res++;
else
res--;
}
return res;
}[/cpp]
That's basically the algorithm. Call generate_planes() with a plane buffer, then for each vertex, call vtx_get_offset() with the plane buffer.
I salvaged a part of another program to project the result onto a 2D surface:
32 planes:
[img]http://img338.imageshack.us/img338/9088/outputdg.png[/img]
512 planes:
[img]http://img12.imageshack.us/img12/1308/outputl.png[/img]
Oh wow, that's a really cool algorithm
[editline]a[/editline]
I guess it's just some kind of spherical noise generator?
I mean, it makes noise that can project onto a sphere with no distortion / stretching and it's also tilable.
Hmm.. seems obvious when you think about it but that's actually really really clever.
Could be used for noise generation if it isn't too expensive or if the generation is done rarely or offline, possibly?
[QUOTE=voodooattack;37458540]Why is "Connect" a guitar?[/QUOTE]
"Get rockin'!"
[QUOTE=esalaka;37458975]Could be used for noise generation if it isn't too expensive or if the generation is done rarely or offline, possibly?[/QUOTE]
Once you've generated the sphere, the algorithm itself is really cheap as it's essentially just make random vector, dot product, compare, multiply for each vertex. Gets expensive with higher poly spheres obviously
Is something considered threadsafe if one thread only reads from a section of memory that another thread reads and writes to? Assuming I properly lock the read-only thread out while the RW one is doing its thing.
Finally got component based entity systems working my engine, I still need to port physics over though.
[QUOTE=dije;37458172]Made a text input field because why not:
-vid-[/QUOTE]
Is this written in C/C++? If you're using glfw you're doing input in a bad way.
glfw has a glfwSetCharCallback() function that grabs unicode characters generated from the keyboard, allowing for modified characters (capslock, shift, alt-codes, etc). As well as supporting foreign keyboards and spaces.
Excuse me if I'm wrong, I'm assuming you're manually grabbing input from each key to generate a string; which is prone to being out of order, is very tedious to make, and is not very portable.
Sorry, you need to Log In to post a reply to this thread.