computer-graphics

How do I display the red channel of an image in Matlab?

I have a 3D matrix im which represents an RGB image. I can do imshow(im) to display the image. I want to display only one of the RGB channels at a time: I want to display the red channel and I want it to appear red. I've tried imshow(im(:,:,1)) but it displays the grayscale image (which is not what I want). How do I display the...

Constrained Panning/Zooming using a ViewMatrix

I'm trying to add constraining boundaries to the Zooming and Panning behaviors I've implemented for Unveil.js (http://github.com/michael/unveil). With boundaries enabled you shouldn't be able to pan outside the scene boundaries and the zoomlevel (=scale) shouldn't ever become lower than 1.0. As a result you shouldn't be able to pan at al...

Projecting a texture in OpenGL

FIXED by setting near clipping plane to 1, rather than 0 (not sure why it was like that to start with). See the question for skeleton code, and Adrian's answer for how and why this works. I have a few different camera positions, and my scene consists of a single quad. The quad is such that it projects exactly onto the viewport/window i...

How to deal with refraction when the rays start inside of a nested object

I am building a simple raytracer for educational purposes and want to add refraction to objects. Using Snells Law, I am able to create a new ray recursively at the intersection points. The raytracer supports currently only spheres and I use a scene where I have multiple spheres nested inside of each other with different refraction indice...

Concave Polygon Line Clipping without Degenerate Edges

I have search and researched the internet last days to find a suitable method for my problem. Problem: Clip a concave polygon against an infinite line without direction (Actually a polygon against a plane in 3d but the problem is similar i think). Currently i use Sutherland-Hodgman but the resulting polygons sometimes contains zero-are...

Function to convert YCbCr to RGB?

I have Y,Cb,Cr values each of 8 bit, can you give me simple C function which converts it to R,G,B each of 8 bit. Here is a prototype of it. void convertYCbCrToRGB(unsigned char Y, unsigned char cg, unsigned char cb, unsigned char &r, unsigned &g, unsigned &b); P.S I am looking for correct conversion forumla only. Because I am finding ...