Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
So I am making a snake game in C but the problem is that it causes a lot of flickering and it also slow downs the game, So I heard that double buffering can solve this but I don't know how to implement that and other ways will also be appreciated. For now I have just reposition the cursor to 0 and disable the visibility of cursor.
The way games typically prevent this "flickering" is due to double buffering. As the current view is being rendered, the back view is performing updates. When the two views swap, the back view clears and performs the updates for the next frame while the current view is being rendered from the previous frame. In Console, you don't have this luxury and when I was writing my snake game in terminal I solved it by not redrawing the entire console every "frame". Rather, I simply drew an empty space over the last tail position and kept the rest of the frame the same. Similar with the snake going over the food, just draw over it with an empty space.
I believe the function I had written was something like this.
void clearlastposition(GameState* state){
_COORD last;
last.X = state->snake.back().partposition.x;
last.Y = state->snake.back().partposition.y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),last);
printf(" ");
}
In my design, the snake body was a vector of snake parts. Where each part contained an x and y position. And the GameState just held an instance to the snake body.
This was done on Windows.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I'm making a simple game using CSFML and am wondering if I can make my code more efficient.
Right now the code looks like this inside the main function's game loop:
// game logic
for (int i = 0; i <= perf.arramount; i++)
{
UpdateBody(&body[i]);
}
// clear
sfRenderWindow_clear(window.window, window.bg);
// draw
for (int i = 0; i <= perf.arramount; i++)
{
sfRenderWindow_drawRectangleShape(window.window, body[i].rect, NULL);
}
// display
sfRenderWindow_display(window.window);
I was told to do things in the order: logic, clear, draw, display. However, would there be any issues with me putting the logic inside the draw loop like this?
// clear
sfRenderWindow_clear(window.window, window.bg);
// draw
for (int i = 0; i <= perf.arramount; i++)
{
UpdateBody(&body[i]);
sfRenderWindow_drawRectangleShape(window.window, body[i].rect, NULL);
}
// display
sfRenderWindow_display(window.window);
Would it slow down the draw calls or make the code more efficient?
I'm not sure if this specific library may be different from others, so even a general answer is appreciated.
How to structure your game is your design decision.
You will be the first to notice problems with it.
But here is my experience. I learned that in the game logic loop you have calculations which are definitly needed, they also tend to need information on how much time has passed. In the drawing loop you just need to visualise the result of the calculations. As soon as you are going to split into threads, the timing of the need to calculate and to visualise will change. You are likely to want to calculate more often than you draw, while you want to draw always completly (except for more advanced FPS-based level of detail rendering....).
So there are multiple aspects which might make you want to keep those two things apart.
What I did was having a calculation step (which by my design gets real time information as a parameter of elapsed seconds) and a separate drawing step. That way you can have them in one parent loop, but you are free to move them at any point AND you are protecting yourself from confusing those two steps.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
When I create a symbol layer the text field is wrapped if the text becomes too long. I'm not able to figure out why/when the text is to long. It seems to depend on different things e.g. font type, text size and text length.
I tested the text length by using this example code. I replace Cafeteria with the alphabet with space between each character. It then wraps to a second line between m and n and that's to few letters on one line for our use case. https://azuremapscodesamples.azurewebsites.net/Symbol%20Layer/Formatted%20text%20field.html
I have been working with mapbox. They have a setting "text-max-width" that solves this issue.
I have checked the javascript code that comes with the npm package azure-maps-control and it doesn't implement support for "text-max-width".
Do anyone know how to fix the wrapping issue or if the package azure-maps-control are going to implement support for the "text-max-width" setting?
There is no option for this today, but I've added it to the feature request list. As a work around, you could do the following:
var layer = new atlas.layer.SymbolLayer(datasource);
map.map.setPaintProperty(layer.getId(), 'text-max-width', 15);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have generated points like this and now I what to connect all these points into one model - spring. How can I achieve this? I've tried iterating through each point and build it from polygons or triangles but I have failed.
I have set of rings where each ring was build from points which coords I have.
You probably want to treat these as generalized cylinders and tessellate a triangle mesh. This can be done by sweeping a circle along the path. Some of the details are tricky since undefined tangents can lead to unexpected twists in your triangle mesh. You might want to study the GLE library or the TubeGeometry implementation in ThreeJS.
For simplestic rendering, note that OpenGL has GL_LINE_STRIP. It also has glLineWidth, although many platforms have a max width of 1. You would need to take care to use separate draw calls for seperate springs, otherwise they'll be connected.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I know there are already other posts about this, but I am unable to get the recommended libraries running.
I am writing a program in C. I am fairly inexperienced at programming. I need to plot the results on an x-y graph. There will be potentially hundreds or even thousands of points. The points will be plotted as the program calculates them, so the graph may need to scroll sideways if the x-axis is exceeded.
So, basically, what I need to do is open a window with x-y axes and plot points in this graph as my program comes up with the numbers. I am looking for the simplest and quickest way to get this written, and it's just a way for me to visualise the results. Can C handle this or do I need a library? If a library, I need one that is easy to set up as my experience is limited.
Thanks in advance
Andrew
If you look for a library to be linked into yours program then MathGL (cross-platform GPL plotting library) is better than gnuplot. At this, it can handle huge data sets, can collect plotting (i.e. add plot, add new plot, add new plot, ..., save current result/plot, add new plot, ..., save result). And MathGL have C interface too.
I'm a bit confused by words "so the graph may need to scroll sideways if the x-axis is exceeded". Because it is difficult to place a point (plot) if one don't know the final axis scale(s).
May be you need just a bitmap (or XPM image - 2D array of char) each row/column is proportional to time-step and the height of point is proportional to data value, like
h[i] = Height*(y[i]-ymin)/(ymax-ymin).
I would use gnuplot if on *nix
http://ndevilla.free.fr/gnuplot/
http://ndevilla.free.fr/gnuplot/gnuplot_i/index.html
Looks pretty easy to me
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Taking one camera and moving it around to take two images of the same object, from a different viewpoint, one should be able to compute a matrix that relates these two scenes. In OpenCV, how is this accomplished?
If said object is a calibration pattern like the chessboard used by OpenCV, then the camera calibration routine mentioned by ChrisO would give you both the camera intrinsics (focal length, principal point, and lens distortion) as well as the camera extrinsics (where they are relatively in space).
If you have general object, then you need to establish a set of 2D correspondences which you can feed into cvFindFundamentalMat. This finds the fundamental matrix which relates the two perspectives. Namely, for each point x in camera 1 and corresponding point x' in camera 2, x'Fx = 0. You can similarly find the epipoles, etc. This uses the 8 point algorithm which requires at least 8 point pairs of point correspondences.
You can get the correspondences either manually or with a robust feature extractor and matcher along the lines of MSER/Affine Harris + SIFT.