OpenGL rotating textured planes in 3D space - c++

I'm wondering if anyone could point me to any resources that would deal in rotating one or several 2D textured planes in 3D space. Something like this but with openGL (preferably C++):
I'm attempting to do pretty much the exact same thing but no matter how I order my operations I'm getting right-screwy results. So I figure asking for some resources on the subject is better than posting tons of code and asking for people to fix my problems for me. :)

If you havent already, do a search for 'NeHe tutorials'. An excellent set of OpenGL tutorials.
Here is a link to the rotation tutorial, includes all the source code in downloadable format and the tutorial walks you through each relevant line.
http://nehe.gamedev.net/tutorial/rotation/14001/
I believe this is working in a 2D space, the step up to 3D probably involves a bit more matrix math but...doable

The NeHe tutorials are a very popular place to learn the basics of OpenGL. In particular, the tutorial about texture mapping should help you:
http://nehe.gamedev.net/tutorial/texture_mapping/12038/
Mind you though that these tutorials are written for older OpenGL versions which are more beginner friendly IMHO.

You should look into scene graphs. Basically it is a way to define a bunch of objects (2D textured planes) and their transforms in 3D space. This allows you to define transforms that work on multiple nodes (objects) as well as single nodes. You can make a pretty simple one in C++ with little effort, or use one such as OpenSG or OSG (slight learning curve needed).
Wikipedia - http://en.wikipedia.org/wiki/Scene_graph

Related

Raycasting render 2d chest CT scans to 3d using OPENGL/C++

I am going to split this question in 3 parts
First, I've been given this problem, and I don't know where to start, if you have been solving related problem, would you give me some hints and keywords to help me do some more research?
I have done some research on my own
So here is some 2D chest CT scans (sorry due to reputation rule i can't implement images directly)
All photos are in the same angle. So I think I can simply read each photo to a vector of pixels, do some thresh holding to make all black and black-ish pixels going to be a non-colored pixel. Next, I'll create a vector called vector_of_photo of those vectors. Then the index of each vector in vector_of_photo are now the Z-index.
Now I can render a 3d photo from those vectors of pixels right?
In the second place, I got trouble understand raycasting algorithm,
I think the idea here is, when I already got a box of pixel then everytime I rotate the box, it cast straight-lines from that angle of the camera to the box, each line found a has-colored pixel going to stop casting and render that pixel (or more specific, copy the pixel to the exactly location on the plane).
Did I understand it correctly?
At last, the OPENGL/c++ part is just the option I think I'm going to use to solve this problem. And I'm not pretty sure it is a good idea or not, so give me some more hint about the programming language, library or module I should take a look at.
I happen to be working on the same problem in my spare time. Haha :)
Here is one approach to your problem:
Load the images into your application, such that you get the 3D volumetric dataset that you describe
Remove all points that don't fit within some range of values (e.g. 0.4/1.0 to 0.6/1.0 brightness). You may need to apply preprocessing and filtering.
Fit a mesh to the resulting point cloud with open-source software. Here is a good blog post about that
https://towardsdatascience.com/5-step-guide-to-generate-3d-meshes-from-point-clouds-with-python-36bad397d8ba
Take the resulting mesh (probably, an STL file) and visualize it in any software your want (Blender 3D, Unity 3D, Cinema 4D, a custom OpenGL application), anything really.
My own approach to this problem is very similar to the one you suggest in your question, and I have already made some headway. Therefore, I thought it would be good to suggest another route.
NOTE Please be aware that what you are working on is not a trivial problem. It's a large project, and there are many Commerical companies that put years into doing just this. This is a great project for learning OpenGL, rendering, and other concepts. It's perfectly doable, but you may be looking at several months of work, and lots of trial and error. Good luck!
Its not often that two people would happen to work on the same problem, so if you want to discuss further, feel free to contact me over linkedin and/or post a comment below. www.linkedin.com/in/michael-sohnen-a2454b1b2

Using mesh gradients in Cairo for coloring a path

I'm a newbie in this type of approach to programming since I really doesn't care for hardcore graphics generation. I design, write, run, and study parametrized climate models with python. But, at last, I have encountered myself with a visualization issue.
I was looking for something in Cairo library that allows me to map a linear gradient onto an arbitrary curve (not necessarily a circumference) such that there is a more or less smooth variation of colour (or shade) across my path. Then I have been looking for some pattern and I finally found that maybe mesh gradients in Cairo are the solution.
However, I can't create a new mesh gradient from my python script with cairo.pattern_create_mesh()!
Therefore, my questions are: How I use mesh gradients in Cairo? Is there any other simple way to do what I want with Cairo (I don't know, like a simple mapping from a line segment to a curve via parametrization, I know I ask too much)?
Mesh patterns were added in cairo 1.12 which is the latest release. Thus, most language bindings likely don't support them yet. I don't know anything about the combination of python and cairo and thus don't know any workaround.
I don't know any simple way to simulate what you need with other patterns, sorry. (Although I am not really sure how you want to do your mapping via mesh gradients either...)

how to draw pool table pockets opengl c++

hey
i am creating a pool table simulator in opengl written in c++
i have the basic table drawn but now i need to add some pockets
i want the pockets to be a basic curve like a C shape
im not quite sure how to do this
i have experimented with trianglefan but iv had no luck
can anyone help please?
also i must add this is part of a university project therefore i will only be using the core opengl and c++....no other tools
thanks in advance
When I use OpenGL, I usually build the models in something like Blender.
Blender is free and allows export to WaveFront obj - an easy format to read in to your program. Or you can use the simple text WaveFront obj with a little scripted editing will produce a list of vertices that you can use in arrays for vertex buffer objects.
I couldn't imagine trying to build objects for a 3D scene using only discrete values and discrete math like (I think?) you're describing.
Do you have access to glu.lib?
http://en.wikipedia.org/wiki/OpenGL_Utility_Library
http://www.opengl.org/resources/faq/technical/glu.htm
That would easily make cylinders or NURBS curves for the pockets. Sample use of it is here: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=18
There is also lots of code from the "Graphics Gems" series available - you can dig through the early books for something suitable if GLU isn't an option.
http://www.graphicsgems.org/
Start with a cube and slice off the bottom corners. Refine as necessary.

Playing with OpenGL

Just learning the basics of OpenGL for a class and was looking for something challenging and interesting to try and draw. Any suggestions?
Aiming to photorealism (just plain models, lights, materials, textures, etc.) is one thing, but what is even more interesting in my opinion is demoscene and all kinds of non-photorealistic effects. The idea of a demo is to program some nice animated graphics that automatically change from one effect to another or tell some sort of a story, and have a background music. Here you can find some videos. Just take a look at what some others have done and use your imagination. That's the funniest part of 3D programming in my opinion. Of course what you'll first program would be something extremely simple when compared to those videos on youtube, but everyone has to start from somewhere. Simple also doesn't need to be ugly. Some random suggestions:
mathematical shapes with sin(), cos(), etc.
alpha blending, especially addition blending (glBlendFunc(GL_ONE, GL_ONE);)
terrain rendering
read 3d model data from a file. (Wavefront .OBJ is a relatively simple one)
feedback effects with glCopyTexImage2D, which copies pixels from screen to a texture (in real life you shouldn't use this because it's too slow, but when learning the basics it's ok)
etc...
You might consider building an OBJ viewer. You will get the experience you're looking for, and it's a pretty good project for a beginning 3D graphics programmer, in terms of difficulty.
I believe opengl has built in shapes such as a teapot that you can call and have it draw. For starters, I'd stick with easy shapes like squares, circles, and cones. Try drawing a wireframe model first since that's the easiest, by using either quadstrips ,triangles or just poly lines. After you've gotten that down, learn to set up lighting and materials so you can draw a solid model.
At school we had a very interesting assignement to get started with OpenGL that I will share. The long term goal was to modelize a living room so you basically have to draw:
A table.
Two chairs.
A carpet.
A sofa
Some stuff that you might find interesting to add on the table for
instance a TV!
When you have all the things done, try to polish the scene a little bit by adding some lighting effects!
Hint: for all the objects you simply need to start with a basic rectangle. Then you can construct your scene step by step using translations/rotations.

How to use opengl to create cylinder effect

I would like to know how to create 'cylinder effect', like the top site feature in safari 4, here is a picture
http://www.macworld.com/article/139022/2009/02/safari4firstlook.html
Can you tell me what should i learn , how to get started?
I would start by working through the OpenGL tutorials on NeHe's website. You might also want to invest in the Red Book. Topics you'll be interested in: Geometry and texture mapping. I think NeHe even has an example of texture mapping on a cylinder.
Depending on what you hope to accomplish, you might be able to use the Visualization Toolkit to draw a texture on a cylinder in 100 lines of code or less. There's a bit of a learning curve to VTK (and OpenGL for that matter), but the vtkTextureMapToCylinder class and the TCL example of how to use it are good places to get started.
Please download iCarousel. It has many types of cylindrical effects in it.Use whichever is useful for you.