• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

412 Neutral

About ViX3LG0N

  • Rank
  1. beginning a snake SFML

    I also thought it would be complicated to make the snake move like in the original snake game, but i came up with this easy idea: for (unsigned int i = snake.size()-1; i > 0; i--) // start with the last element(body part) { //snake[i] = snake[i-1]; // works for my code //you would have to use snake[i].lastX = snake[i-1].lastX; and snake[i].lastY = snake[i-1].lastY; } Its important that your "snake-head" is the 0th element of the snake vector. I have just a vector<vec2> snake (vec2 is just x and y). So every time you move your snake-head in any direction the x and y of the next body-block just becomes the old head position(or the position of the block in the vector before it).
  2. 1. The feature you are trying to implement is called "Automapping". 2. SDL is used for opening a window with a context to display stuff on it and handles also the input. You have to think about if you want to use the SDL integrated 2D draw library or if you want to use OpenGL to draw your stuff. I can recommend you used OpenGL as it is easy to begin with, but also has endless level of complexity if you want to. Also there are a lot of tutorials for SDL+OpenGL 2D 3. The next problem would be you need to draw text in an SDL context, with OpenGL it could be hard for you to do text rendering. If you pick the SDL drawing library just use SDL_ttf. 4. I would do automapping with std::vector, so you have "dynamic arrays" and your level can grow struct Location { int x; int y; }; vector<Location> automap; void moveTo(int xPos, int yPos) { //Check if you already exploared this location bool alreadyAdded = false; for (unsigned int i = 0; i < automap.size; i++) { if (automap[i].x == xPos) { if (automap[i].y == yPos) { alreadyAdded = true; } } } if (!alreadyAdded) { Location tmpPos; tmpPos.x = xPos; tmpPos.y = yPos; automap.push_back(tmpPos); } } Lets say the location "middle in the forrest" is on position x:0 y:0 and if you start the game you call "moveTo(0,0);" Your Player moves to the north then call "moveTo(0,1);". Also its better if you make variables for the player-position and just call "moveTo(player.x,player.y)" every time you move to another location and also change the postion so if you go to the north just do "player.y++;" and call "moveTo(player.x,player.y);". The only thing you need to do now is draw the actual map(which should be correctly automapped with my theorie of automapping). But this is your decision on how to do that, if you choose OpenGL, i can help you again.   Hope this helps you a bit 
  3. Hey, I try to get working animations with Assimp. As you can see in the picture, head and lamp are correctly transformed, but the body isnt. Also notice the holes in the body. I think the problem is that the body is transformed by multiple bones. [attachment=17287:assimp.png]   My code is designed that the whole model is splitted into single meshes (Assimp does this). So each mesh has its own VBO with vertices, normals, uvs, weights ...   The bonematrices should be correctly calculated each frame. But maybe im uploaded them wrong to the shader: for (unsigned int m = 0; m < scene->mNumMeshes; m++) { /*...*/ if (scene->HasAnimations()&&scene->mMeshes[m]->HasBones()) { /*...*/ for (unsigned int i = 0; i < 100; i++) { mat4 tmpMat = mesh[m].bonemat[i]; string loc = "gBones["+convertInt(i)+"]"; glUniformMatrix4fv(glGetUniformLocation(shader, loc.c_str()), 1, GL_FALSE, value_ptr(tmpMat)); } /*...*/ } /*...(Draw)...*/ } Also im not sure if filling up the bonedata(bonematrix+weight for each vertex) is correct: for (unsigned int m = 0; m < scene->mNumMeshes; m++) { /*...*/ if (scene->HasAnimations()&&scene->mMeshes[m]->HasBones()) { for (unsigned int k = 0; k < 100; k++) { mesh[m].bonemat[k] = mat4(1.0); } for(unsigned int i = 0; i < scene->mMeshes[m]->mNumVertices; i++) { ivec4 tmpID; vec4 tmpW; for (unsigned int h = 0 ; h < 4; h++) { tmpID[h] = 0; tmpW[h] = 0.0; } mesh[m].boneIDs.push_back(tmpID); mesh[m].weights.push_back(tmpW); } for(unsigned int i = 0; i < scene->mMeshes[m]->mNumBones; i++) { for (unsigned int j = 0 ; j < scene->mMeshes[m]->mBones[i]->mNumWeights ; j++) { int v = scene->mMeshes[m]->mBones[i]->mWeights[j].mVertexId; float w = scene->mMeshes[m]->mBones[i]->mWeights[j].mWeight; //check if is filled int notFilled = -1; for (unsigned int h = 0 ; h < 4; h++) { if (notFilled == -1) { if (mesh[m].weights[v][h] == 0.0) { notFilled = h; } } } mesh[m].boneIDs[v][notFilled] = i; mesh[m].weights[v][notFilled] = w; } } } /*...*/ } If this code is out of context for you, i linked the whole Model class from my dropbox account. Model.h Model.cpp   Hopefully we find a solution
  • Advertisement