Struggling with 2d platforms physics - rust

Im making a game in Rust(Im a beginner) for my son and am somehow struggling with platforms - specifically modifying their length. I can get the platforms if i use certain numbers but if i try to modify the platform width I run into problems.
If i use the const PLATFORM_WIDTH=400 then everything works fine (i seemingly can make any number of them and it all works), but I don't want to have platforms of a fixed width (length), I want each platform to be of variable width. If I try to make the platform width say 100.0 then it is rendered correctly but I can walk over empty space as if there was a platform there. If I make them greater than 400 they are rendered but the sprite will fall through solid floor at some points.
Really don't know where Im going wrong and this annoying issue is preventing me from making progress on my game.
Id really appreciate if someone could take a look at my code and tell me where im going wrong.
My code is here:
https://github.com/country-bumpkin-software/rusty-miner/blob/main/src/main.rs
Also can someone explain to me why the Rect function seems to take negative numbers for the x, y coords?

The problem is that you sometimes use the width from the platform struct (e.g. when checking for intersections on line 264) and sometimes use the PLATFORM_WIDTH and PLATFORM_WIDTH_HALF constants (e.g. when drawing the platform on line 346).

Related

Vector3.ToString "rounds" decimals after build

I'm trying to get very precise Input.mousePosition in Unity3D with Input.mousePosition.x.ToString("F4"); and in the editor everything works fine. I get 4 decimal signs exacly how I need it. However, after I build the app, I get x.0000 all the time.
What important is, that, in the editor, I don't get zeroes only when I choose precise resolution and not the aspect ratio or Free Aspect. I was trying to play around with build resolution settings, for example disabling all aspect ratios, setting exact resolution, windowed/fullscreen mode. Nothing helps so far.
It seems like the built app sort of disables inbetween pixel position, and I have no idea why.
I know that there are plenty of questions and info on vector3 decimals, but my problem is mostly about display resolution (inbetween pixel coordinates) in Unity. Thanks in advance for any advice.

SDL2 + openGL ES 2.0 frame rate performance boost with less CPU load

I am developing on a linux system using latest (at the moment) SDL2 (2.0.8) + openGL ES 2.0 (GLSL 1.0) eventually targeting a raspberry pi 3 board. I have so far done a few things like drawing text with freetype, drawing lines, text boxes (editable), text lists, waveform boxes (all i need to pass to a function is an array of vertices) and other shapes with glDrawArrays(). Now, there are things that need to be refreshed at, let's say, 10 times per sec and others that need 1 time per second. What would be the best approach to skip re-rendering everything at the rate of 10 times per sec? Because obviously openGL works by drawing everything from scratch on every 'frame'. However i know and you know that other approaches exist that include: rendering on top of the screen you already have or taking a screenshot and rendering on top of it only the fast changing things as well as other solutions. What do you thing would be the best approach to skip re-doing everything before calling SDL_GL_SwapWindow() ? How can i take a screen shot and render it on the invisible buffer then render only the fast changing objects and then call SDL_GL_SwapWindow() ?
This is a screen shot of the app so far drawing basic things
Thanks in advance.
i eventually had to realize that i should not have posted the question in the first place but since this is a place where people learn from others i now feel somewhat nicer :) . So, the thing i had to do was to simply stop clearing the invisible buffer (i will call it that for simplicity) and render on top of it only controls that change. Those that change are updated by covering the area that they take by a rectangle and then draw new stuff on that area. I have already done it and the frame rate just 'exploded'. I do not really think that there is a better approach since the way i do it requires no action at all. All i had to do was to add a few if conditions that selectively rendered or skipped every time the execution reached the point where functions iterate through the controls that have to be drawn on screen and therefore decide what to render and what not. However a well thought set of structures is required for every control instead of declaring and defining endlessly global variables which will only makes things confusing and difficult to maintain.
Regards to all.

GtkFrame mystery: Different looks each time the program is started

This is really confusing the heck out of me. Take a look at this screenshot:
Sometimes, the GtkFrames in my program look like on the left side, and sometimes they look like on the right side - or even a mix of the two! The program is exactly the same. Just running the same program multiple times yields very different looks of the GtkFrames in the program! How can that be?
It seems that there are two different designs of GtkFrame:
The first one has its label centered at the top of the frame and
smoothly dissolves towards the
bottom so that the frame doesn't completely enclose the GtkFrame's
contents.
The second design has its label left-aligned at the top of the frame
and draws a border around the complete GtkFrame.
The problem is now that GTK+ seems to choose one of the two designs entirely at random. I don't see any pattern in which design I'm going to get. It appears to happen completely at random which is really confusing me.
Can somebody shed a light onto this mystery? What is going on here? Is there a way to force GTK+ to use a certain design?
I'm using GTK+ 2.24.10 with the Adwaita theme on Linux Mint.

OpenGL 3.2 Core Sprite Batch Example?

I have been tearing my hair out for a while over this. I need an OpenGL 3.2 Core (no deprecated stuff!) way to efficiently render many sprites, using batching (no instancing).
I've seen examples that do this with geometry alone, but mine also needs to send textures to it, I don't know how to do this.
I need a well done example of it working in action. And looking at how other libs like monogame and such do it isn't much help, because all I'm interested in is the GL code, and it has to have no deprecated stuff in it.
Basically I want to be able to efficiently render thousands+ of sprites, all having textures. The texture is just a spritesheet, so I just need to tell it to render a region of that spritesheet.
I'm disappointed in the amount of material available for programmable pipeline. To the point where it seems like it'd be so much easier to just say screw it and use fixed pipeline, even though I definitely don't want to do that.
So yeah, any full examples that do what I want? Or could somebody more knowledgable write one up? :)
A lot of the examples are "oh, here's how you render 1 triangle". Well that's great, except nobody needs to render only 1 triangle/quad. And they need to be textured in addition to that!
An example that uses VBOs/VAOs/EBOs
ALSO: this means the code can't use glTexPointer and that stuff, but just in raw VBOs/VAOs...
I saw this question and decided to write a little program that does some "sprite" rendering using points and gl_PointSize. I'm not quite sure what you mean by "batching" as opposed to "instancing," but my program uses the glDrawArraysInstanced() call so that I can render multiple points without needing my VBO to be variable sized. My code also doesn't texture the sprites, but that's easy enough to add in (upload the active texture index (the one that was active during your call to glTexSubImage), to a GLSL sampler2D using glUniform1i).
Anyway, here's the program I wrote: http://litherum.blogspot.com/2013/02/sprites-in-opengl-programmable-pipeline.html Hope you can learn from it!

How do I create a real-time rendering window from scratch?

I've been studying 3D graphics on my own for a while now and I want to get a greater understanding of just how everything works. What I would like to do is to create a simple game without using DirectX or OpenGL. I understand most of the math I believe, but the problem I am running up against is I do not know how to get control of the pixels being displayed in a window.
How do I specify what color I want each pixel in my window to be?
I understand I will probably run into issues with buffers and image shearing and probably terrible efficiency problems, but I want to create my own program so that I could see from the very lowest level, of the high level language, how the rendering process works. I really have no idea where to start though. I've figured out how to output BMPs, but I would like to have a running program spitting out 20+ frames per second. How do I accomplish this?
You could pick a environment that allows you to fill an array with values for pixels and display it as a bitmap. This way you come closest to poking RGB values in video memory. WPF, Silverlight, HTML5/Javascript can do this. If you do not make it full screen these technologies should suffice for now.
In WPF and Silverlight, use the WriteableBitmap.
In HTML5, use the canvas
Then it is up to you to implement the logic to draw lines, circles, bezier curves, 3D projections.
This is a lot of fun and you will learn a lot.
I'm reading between the lines that you're more interested in having full control over the rendering process from a low level, rather than having a specific interest in how to achieve that on one specific platform.
If that's the case then you will probably get a good bang for your buck looking at a library like SDL which provides you with a frame buffer that you can render to directly but abstracts away a lot of the platform specifics issues. It has been around for quite a while and there are some good tutorials to give you an idea of whether it's the kind of thing you're looking for - see this tutorial and the subsequent one in the same series, which should be enough to get you up and running.
You say you want to create some kind of a rendering engine, meaning desinging you own Pipeline and matrice classes. Which you are to use to transform 3D coordinates to 2D points.
When you have got the 2D points you've been looking for. You can use say for instance on windows, you can select a brush and draw you triangle values while coloring them at the same time.
I do not know why you would need Bitmaps, but if you want to practice say Texturing you can also do that yourself although off course on a weak computer this might take your frames per second significantly.
If you aim is to understand how rendering works on the lowest level. This is with no doubt a good practice.
Jt Schwinschwiga

Resources