I'm writing a program to draw a three-dimensional cube (with a corner cut off) without using any 3D graphics APIs. The only API call I make is win32's SetPixel()
Everything is going great. I've drawn lines, faces, and even the entire cube. Then rotation came along.
For some reason, when I rotate my cube, it begins to shrink. I became confused, then I realised something. Floating point numbers are truncated.
Here's some code that is fired everytime the user presses 'X' on the keyboard.
Code:
p->setY( p->getY() * cos(5.0/180.0*PI) - p->getZ() * sin(5.0/180.0*PI));
p->setZ( p->getY() * sin(5.0/180.0*PI) + p->getZ() * cos(5.0/180.0*PI));
p is a Point object that I created. Here the Y value and the Z value of the Point are being set. The problem is everytime X is pressed, and this code is fired, a small amount of precision is lost. As a result, the cube shrinks.
I'm really completely stumped. I remember when studying assembler that floating point numbers can be truncated or rounded. I think rounding would solve my problem. Since 50% of the time the value would round up, and 50% of the time the value would round down.
Whereas with truncation values are always lost, and never gained.
Linkage between two scripts
Okay say I have this for a link in a script:Code: <li><a href="#" onclick="ajaxpage('bio', 'content'); return
AutoChoosing a CSS file based on URL
Hey everyone,I have a site that has multiple URLs and CSS files.Based on the URL that the user goes to I want that CSS file to load.This is what I have thus far in the <head> of my
Registration
ok so i have a site where people can register and login which works now thanks to someone on here that pointed out my error :-)Now my users click my links they can view the content without logging in,
Bit manipulation program with binary operations
My homework is to create a program to scan in and add binary numbers and print them like so
private constructor
Hello,Can we create a constructor as private? If yes, what is the use of it? If no, why can't we make it?Please suggest...Thanks
simple php table loop
Hi all,I've the following code <?php // Create category options $query = "SELECT * FROM categories ORDER BY category ASC"; $result = mysql_query
Changes to hosting company's server has affected web contact form
I started a thread a couple of months ago about the contact forms on my client's website. Basically he wants me to overhaul the SEO on his site. However, there were problems with the PHP contact forms
Create multiple (n) arrays
Hi there,I have the following need:I have 2 arrays (coming from a databases)Array2 is related to Array1 -Example:Array1Dog, abcCat, bcdHorse, cdeArray2,meat, abcbones, abcfish, bcdgrain, cdegrass,
Get dump of MySQL DB from Live Site
I'm after an easy, but secure way of generating and importing a MySQL dump from a remote server. The way I want to achieve this is as follows: 1) I will have a page on my localhost server with a form
How do I create a 2D game "camera" to follow player?
In J2ME programming I'm targeting MIDP 2.0 devices.I'm using gamecanvas and I was thinking that I could create my full world (640 x 480) using a TiledLayer and then set the refpixel of the TilerLayer