2d game engine clipping algorithms - c++

I'm building a 2d game engine using c++ and opengl. Now i have implemented a scene graph and now every node of this graph is being rendered every frame. What are good algorithms for clipping nodes that are outside the viewport?

at a most simple level, you could use quadtrees for culling, it has the added bonus of being useful for collision detection as well, Wikipedia has a page explaining it.

Related

Replicating 2.5d y-shearing in GLUT/FreeGLUT

I am using FreeGLUT to make a 3D engine for my future games, purely because it is easier to deal with than modern OpenGL, the intention is to be a simple engine that has similar features to the IDTech1/ACKNEX-3/Build Engine.
Until now I have been using a projection matrix like any normal 3D engine, consequently the 2.5D engine look that is targeted is not achieved, especially when rendering sprites on the map as the player looks up and down, they distort instead of keeping the straight proportion.
To mitigate this, instead of just locking the camera so that the player can't look up and down, I decided it was better to try to replicate the y-shearing effect that the old engines had to disguise the "true 3D" projection.
Unfortunately, I have not found any material on methods to help me do this, is it not possible to replicate such an effect in GLUT?
"True 3D" projection / 2.5D projection with y-shearing (desired):

SDL Tile and Sprite Rendering Terrain

Hello recently i started to mess around with SDL. Since i was interested in some 2D/2.5D games.So i started messing around with SDL in C++, I was looking to recreate something similar to Original Zelda.
So as far as i understand those game work with some kind of isometric prespective, or standard Orthogonal view but one thing i do not understand is how can you generate 3D-like Collisions between those objects on the map (tiles, sprites etc which are in 2D). Have a look at the video link below. Is this created purely in SDL, is it PerPixel collision or rectangular ? Or it might involve OpenGL as well ?
Link: https://www.youtube.com/watch?v=wFvAByqAuk0
The original was probably a simple Rectangular collision.
I believe that your "3D collision" is the partial collision present in some objects. For example, Link can go through the leaves, but not through the trunk.
You can do it easily in 2 ways:
Layers of rendering and collision. The trunk is located in one layer and is covered by some collision boxes. Link is present in a intermediary layer. And the leaves are in another layer, on top of Link. Then you can check collision between Link's Layer and the layer with the trunk and other objects, for example.
Additionally you can create a property for your tiles in which you can store the type of collision you hope to obtain. For example, 'box' collision will tell your engine that the object is collidable on every side. Or 'bottom' collision will tell your engine that Link will collide with this object only if he is walking down into the object (this is the effect of you will see on some 2D sidescrollers: jump through a tile but then fall into it solid.
Per pixel collision in those simple cases is not worth it. I find it much better to personalize the collision ourselves, using creativity, masks and layers.
BTW: This topic would fit better on https://gamedev.stackexchange.com/

Drawing area graph in directX

I have an MFC application to draw graph using DirectX. Now I have to add the feature to draw the area graph in DirectX.
Now my application draws like this..
I want to include the feature to my graph to look like this..
here I have to fill the graph area with some color.
I have tried DrawPrimitive(). but this could be used to draw the Triangle, rectangle. but in my application I would like to draw graph with random data points.
Is it possible to achieve in DirectX..?
Kindly someone provide your suggestions.
If u need 2d graph's alone Direct2D is a great option,But if you insist on going to 3D for greater animation and illustrative purposes you can uses OpenGL.There are plenty of custom controls for graph illustration purposes based on OpenGL.
For eg:
http://www.codeproject.com/Articles/4346/D-Graph-ActiveX-Control
Opengl has greater flexibility and can serve your needs better since it is of open source.
hope this helps and Good Luck

Tilemap 2D realistic fluid physics

I'm interested in trying to create realistic fluids (water), for a 2D game. This game is similar to Terraria. I have heard about how you can slap a bunch of colliding particles on the scene and render over it and voila, realistic acting water.
Terraria uses tile based water, which I am not a fan of.. I want something more advanced.
I thought about using bullet 3D physics (box2d has limits I would hit). For non colliding particle effects, I am thinking about using something like SPARK, since I think that'd give me the best of both worlds.
The issue I am thinking about, is that each block is 16x16, so on a 1600x900 scene, there are about 5 thousand tiles.
So I need to tell the physics engine that these tiles are collidable. Of course, there are void tiles that are considered to be non collidable.
Does anyone have ideas on this? Language is C++, I doubt that's relevant though.
EDIT: i think i'm going to have to cave in and use grid based water. I suppose, in retrospect particle based just makes everything more difficult but for what gain?
Your question is about tiled fluids, but you seem to actually be asking about a particle based approach.
If that's the case, what you're looking for is "Smoothed Particle Hydrodynamics", or SPH, which is a very popular technique for 2D and 3D fluid simulations in realtime situations.
Yes, it's basically just a particle system, with each particle responding to the forces in your environment (gravity, collisions etc.) in a reasonable (mathematically stable) way, combined with a constraint that they must stay a certain distance apart in order that the fluid is incompressible.
You can render the particles as points, if you have enough of them, or you can use them as a source for deriving a surface (for example using marching-cubes, though in 2D I wouldn't worry about that).
http://en.wikipedia.org/wiki/Smoothed-particle_hydrodynamics
It has the advantage of being relatively easy to code, and indeed to accelerate on a GPU.
Indeed I think they're probably a better approach than trying some kind of tile-based approach, and you get some more interesting results, such as spray kicking up, waves kicking against the edges of objects, etc. It's not too hard to get something pleasing working, I'd give it a go.

3d modeling in cuda (raytracing pre-stage)

I'm trying to implement a simple raytracing code using CUDA.
I'm stuck at the modeling part. im trying to figure out how to model a 3d space with objects (start with a simple 3d space containing a 3d cube in the middle).
i've read about hybrid projects with openGL and CUDA but those articles were too general - and
as i said i am new at this.
are there any libraries/code for implementing such a 3d model?
If you want to do ray tracing in CUDA, take a look at NVIDIA's OptiX, which is an API for GPU-accelerated ray tracing. There are several example codes in the SDK ranging from simple to sophisticated. They will demonstrate how to model 3D objects in your renderer.
On the other hand, if you're new to both CUDA and ray tracing, you probably don't want to tackle both at once :)