Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

112 Neutral

About Fiodis

  • Rank
  1. That was the problem, thanks guys.  Since the entity vector and the group vector are both accessed through their parent Scene, giving access to both when I need them shouldn't be a problem.  I don't know why I didn't just store indices to start with; I guess I thought there'd be more overhead using the index to access another vector than using a pointer/reference directly.  Ah well; wherever the bottleneck is going to be, it's probably not going to be in the difference between entList[groupList[0].entIndex[0]] and groupList[0].entities[0].     Thanks again! 
  2. After reading about them, I've been trying to switch over from an OOP setup to using an entity-component system, but I've had some trouble with dependencies.  For example, an entity might want to help members of the same team, so when the AI system is doing processing on that entity's components, it needs a list of other entities on the same team.  I saw some examples maintained a list of pointers to entities on the same team, so I tried doing something similar: I defined a Group struct that contains a label and a vector of pointers to the entities that make up that Group: struct Group {     std::string name;     std::vector<Entity*> entities; }; Both Entities and Groups are contained in larger objects called Scenes, which have as part of their constructor: entList.push_back(Entity());// First entity added to a std::vector<Entity> called entList     entList[0].entName = std::string("Cam0"); groupList.push_back(Group());//First group added to an std::vector<Group> called groupList     groupList[0].name = std::string("Cameras");     groupList[0].entities.push_back(&entList[0])// Hopefully adds a pointer to the first entity in the Scene's entList This way I can easily and directly access entities in a specific group without having to iterate all the time over ever entity in the entList.  The entity list itself seems to be working fine, but I have trouble whenever I try to access entities through the groupList.  Code like the following gives me an access violation error: Scene scn = Scene(); std::cout << "\n" << scn.entList[0].entName;// This works std::cout << "\n" << scn.groupList[0].entities[0]->entName;// This gives me an access violation I think there's something wrong with my understanding of pointers.  This thread presented a problem similar to mine, with the suggestion that the OP had made a pointer but hadn't initialized it yet.  I'm pretty sure I'm initializing it to &entList[0] with the line groupList[0].entities.push_back(&entList[0]); but maybe vectors of pointers work differently.  A google search for "C++ vectors of pointers" didn't seem to indicate that, though.  push_back ought to copy the given value to a new element at the vector's end, no?  So it should be initialized.     In another attempt to debug, I tried making the following change in Scene's initializer: groupList.push_back(Group());//First group added to an std::vector<Group> called groupList     groupList[0].name = std::string("Cameras");     groupList[0].entities.push_back(NULL)// Initialize it to NULL grouplist[0].entities[0] = &entList[0];// Change it to point to the first entity in the Scene's entList. Then this runs fine and outputs the text "not null": if (groupList[0].entities[0] != NULL) std::cout << "not null" Which makes me think even more that the initialization is going fine, but then why am I still getting an access violation error whenever I try to access that entity's members through the group's pointer list? Perhaps it's a simple error but it's driving me mad trying to find it; all the tutorials I re-read about pointers convince me I've got the right idea, but somehow I must not.
  3. I've followed this tutorial for a custom ray-obb intersection test, but I'm having some trouble with my implementation.  I'm not even sure what the behavior is like; from one viewpoint the intersection tests positive all over the screen, but when I move right half a unit it tests false almost everywhere.  I'm pretty sure I'm passing in the correct ray, and that the problem lies in the intersection test function.  Here it is: bool TestRayOBBIntersect(glm::vec3 rayOrigin, glm::vec3 rayDir, glm::vec3 aabbMin, glm::vec3 aabbMax, glm::mat4 ModelMat, float& intersectDistance){ float tMinX = 0.0f, tMinY = 0.0f, tMinZ = 0.0f; float tMaxX = 100000.0f, tMaxY = 100000.0f, tMaxZ = 100000.0f; float xDist, yDist, zDist;   glm::vec3 obbPos = glm::vec3(ModelMat[3].x, ModelMat[3].y, ModelMat[3].z); glm::vec3 delta = obbPos - rayOrigin;   // X axis glm::vec3 xaxis = glm::vec3(ModelMat[0].x, ModelMat[0].y, ModelMat[0].z); float e = glm::dot(xaxis, delta); float f = glm::dot(rayDir, xaxis);   float t1 = (e+aabbMin.x)/f; float t2 = (e+aabbMax.x)/f; if (t1 > t2){ float w = t1; t1 = t2; t2 = w; } if (t2 < tMaxX) tMaxX = t2; if (t1 > tMinX) tMinX = t1; if (tMaxX < tMinX) return false;   xDist = t1;// Distance to the nearest intersection in x   // Y axis glm::vec3 yaxis = glm::vec3(ModelMat[1].x, ModelMat[1].y, ModelMat[1].z); float g = glm::dot(yaxis, delta); float h = glm::dot(rayDir, yaxis);   float t3 = (g+aabbMin.y)/h; float t4 = (g+aabbMax.y)/h; if (t3 > t4){ float w = t3; t3 = t4; t4 = w; } if (t4 < tMaxY) tMaxY = t4; if (t3 > tMinY) tMinY = t3; if (tMaxY < tMinY) return false;   yDist = t3;// Distance to the nearest intersection in y   // Z axis glm::vec3 zaxis = glm::vec3(ModelMat[2].x, ModelMat[2].y, ModelMat[2].z); float i = glm::dot(zaxis, delta); float j = glm::dot(rayDir, zaxis);   float t5 = (i+aabbMin.z)/j; float t6 = (i+aabbMax.z)/j; if (t5 > t6){ float w = t5; t5 = t6; t6 = w; } if (t6 < tMaxZ) tMaxZ = t6; if (t5 > tMinZ) tMinZ = t5; if (tMaxZ < tMinZ) return false;   zDist = t5;// Distance to the nearest intersection in z   intersectDistance = sqrt((xDist*xDist + yDist*yDist + zDist*zDist));// Total distance to nearest intersection   return true; } Also, is this an OBB intersection test, or an AABB intersection test?  I'd assume the rotation is present in the model mat, but the source code on the tutorial page has references to an AABB.  
  4. Fiodis

    Perlin noise trouble

    I do have a simplex noise implementation which I grabbed off the internet that looks quite nice, but I was hoping to create my own to better understand what goes on inside the magic box.  Just looking at the implementation I have is a bit overwhelming, though; it's not very well commented and I don't know where to start.     Is there an actual perlin, not value, noise tutorial out there which you'd recommend?  I tried searching for "Perlin noise tutorial" but got some six reworded versions of that same value noise tutorial, all with the same results once I implemented them.  
  5. Hello Gamedev.net!  I've been lurking about for a few months reading tutorials, but only just now got around to making an account.     Anyway, I recently read this quite easy to understand perlin noise tutorial.  I tried to build my own perlin noise function closely following it, but when I try to fill a bitmap it creates an image of TV-like static with some repeating elements: When I divide the input pixel coordinates by 64, which has the effect of zooming in, it looks a bit more like noise, but it's horribly blocky: Searching, I found an old thread on the subject here, but wasn't able to glean a solution from it.  I appear to be missing something here - perhaps I'm casting a float to an int or something where I shouldn't be, and losing some information.  The code: float intNoise(int x, int which){// which determines which of the five random number generators below to use if (which == 1){ x = (x<<13)^x; return (float)(1.0f - ((x * (x * x * 15731 + 789221) + 1376312589) & 2147483647)/ 1073741824.0); } else if (which == 2){ x = (x<<13)^x; return (float)(1.0f - ((x * (x * x * 89107 + 300109) + 800143) & 2147483647)/ 973801.0); } else if (which == 3){ x = (x<<13)^x; return (float)(1.0f - ((x * (x * x * 58937 + 351991) + 832883) & 989171)/ 1073741824.0); } else if (which == 4){ x = (x<<13)^x; return (float)(1.0f - ((x * (x * x * 44417 + 390991) + 865847) & 2147483647)/ 1073741824.0); } else if (which == 5){ x = (x<<13)^x; return (float)(1.0f - ((x * (x * x * 35803 + 399983) + 1376312589) & 2147483647)/ 1073741824.0); } } float cosineInterpolate(float a, float b, float x){ float ft = x * 3.1415927f; float f = (1.0f - cos(ft)) * 0.5f; return (a * (1.0f - f)) + (b * f); } float noise2DPure(float x, float y, int which){ float n = x + y * 57; return intNoise(int(n), which); } float smoothNoise_2DPure(float x, float y, int which){ float corners = (noise2DPure(x-1.0f, y-1.0f, which) + noise2DPure(x+1.0f, y+1.0f, which) + noise2DPure(x-1.0f, y+1.0f, which) + noise2DPure(x+1.0f, y-1.0f, which))/16.0f; float sides = (noise2DPure(x, y-1.0f, which) + noise2DPure(x, y+1.0f, which) + noise2DPure(x-1.0f, y, which) + noise2DPure(x+1.0f, y, which))/8.0f; float center = (noise2DPure(x, y, which))/4.0f; return center + sides + corners; } float interpolateNoise2DPure(float x, float y, int which){ int integer_X = (int)x; int integer_Y = (int)y; float fractional_X = x - (float)integer_X; float fractional_Y = y - (float)integer_Y; float v1 = smoothNoise_2DPure((float)integer_X, (float)integer_Y, which); float v2 = smoothNoise_2DPure((float)(integer_X + 1), (float)integer_Y, which); float v3 = smoothNoise_2DPure((float)integer_X, (float)(integer_Y + 1), which); float v4 = smoothNoise_2DPure((float)(integer_X + 1), (float)(integer_Y + 1), which); float i1 = cosineInterpolate(v1, v2, fractional_X); float i2 = cosineInterpolate(v3, v4, fractional_X); return cosineInterpolate(i1, i2, fractional_Y); } float perlinNoise2DVary(float x, float y, float persistence, int octaves){ float total = 0; float p = persistence; int n = octaves - 1; for (int i = 0; i <= n; i++){ float frequency = powf(2.0f, (float)i); float amplitude = powf(p, (float)i); total += interpolateNoise2DPure(x * frequency, y * frequency, i+1) * amplitude; } return total; } // Bitmap fill: int main(int argc, char argv[]){ const unsigned int res = 256; float min = 1.0f; float max = 0.0f; unsigned char *picArr = new unsigned char[res*res*3]; for (unsigned int i = 0; i < res; i++){ for (unsigned int j = 0; j < res; j++){ picArr[3*(i*res + j)] = char(int(((perlinNoise2DVary((float)i/64.0f, (float)j/64.0f, 1.0f, 5))/2000.0f * -1.0f) * 255)); picArr[3*(i*res + j) + 1] = char(int(((perlinNoise2DVary((float)i/64.0f, (float)j/64.0f, 1.0f, 5))/2000.0f * -1.0f) * 255)); picArr[3*(i*res + j) + 2] = char(int(((perlinNoise2DVary((float)i/64.0f, (float)j/64.0f, 1.0f, 5))/2000.0f * -1.0f) * 255)); } } unsigned int testInt = SOIL_save_image("perlin.bmp", SOIL_SAVE_TYPE_BMP, res, res, 3, &picArr[0]); delete[] picArr; } The function also appears to return a value between 0.0 and -1000.0.   Also, calling the function with just one octave causes the bitmap to be purely black.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!