In this exercise you will create and place a series of boxes to create a 3D bar plot. Next you will expand on the bar plot and add colors and text labels for each bar.
In visualization, the size and position of shapes are often set using the results of a mathematical function or simulation. This example uses a simple C program that computes a sine wave. Your task will be to modify this program to output VRML to build a bar at each step along the sine wave.
This exercise focuses upon use of Shape, Box, Text, Appearance, Material, FontStyle, Transform, and Billboard nodes.
View the resulting VRML scene by loading the "barplot.wrl" file into your browser.
The bar plot program generates bars that are all white. Your task is to modify the barplot1.c program to add color to each bar. Make the color of each bar a function of the bar's height.
HINT: You will need to declare variables at the top of
the program to contain the color values:
HINT: You will need to compute colors based on bar height.
A nice color scheme is a ramp from blue to red:
Recompile and run the new barplot1 program, and view the resulting VRML scene (call it "barplot1.wrl").
SOLUTION: barplot1.c, barplot1.wrl
The bars on a bar plot give a quick over-all impression of the changing values of a function, like a sine wave. Numeric labels on bars are often used to show the actual value for each bar. Your task is to modify the barplot2.c program to add a numeric text label for each bar. Put the label above the bars that go up from the horizontal zero-line, and put the labels below the bars that go down.
HINT: When the function goes negative, you need to account for the negative offset when positioning the text labels. Here's a piece of code that computes a "nice" text offset:
HINT: The default text font size is too large. You will need to add a FontStyle node to the label's Text node.
HINT: To center the text, you can set the justify field of a FontStyle node to:
SOLUTION: barplot2.c, barplot2.wrl
When you spin the bar plot around, the flat text labels disappear when viewed edge-on. Your task is to make the text labels always face the viewer.
HINT: To enable the labels to orient themselves without reguard to any viewer orientation, you can specify a special axis of rotation in the Billboard node:
SOLUTION: barplot3.c, barplot3.wrl