Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - 3D Vector program trouble.

3D Vector program trouble.

Postby MarzAstral on Thu Aug 05, 2004 11:26 pm

i'm trying to make a program that displays a 3d cube spinning on the screen, i'm having trouble. I think the problem lies somwhere in the sin() and cos() functions. for some reason the sine and cosine tables have negative values in them and i don't know why. maybe one of you guys can help me out. Here's the code. have fun with it.



float cosine_table[256], sine_table[256];
float obj_x:?:, obj_y:?:, obj_z:?:;
float world_x:?:, world_y:?:, world_z:?:;
int screen_x:?:, screen_y:?:;
int lines_1[10], lines_2[10];
int viewer_distance = 256;

new_z(int y_angle, float z, float x)
{
float new;
new = x * sine_table[y_angle] + z * cosine_table[y_angle];
return new;
}

new_x(int y_angle, float z, float x)
{
float new;
new = x * cosine_table[y_angle] - z * sine_table[y_angle];
return new;
}


screencoor_x(float world_x, float world_z)
{
return viewer_distance * world_x / world_z + 120;
}

screencoor_y(float world_y, float world_z)
{
return viewer_distance * world_y / world_z + 160;
}

table_init()
{
int i;
for(i=0;i<256;i++)
{
cosine_table[i]=cos(i*6.28/256); // <--- i think the problem lies in these two expressions.
sine_table[i]=sin(i*6.28/256); // <---
}
}

draw_obj()
{
line(screen_x[0], screen_y[0], screen_x[1], screen_y[1]);
line(screen_x[1], screen_y[1], screen_x[2], screen_y[2]);
line(screen_x[2], screen_y[2], screen_x[3], screen_y[3]);
line(screen_x[3], screen_y[3], screen_x[0], screen_y[0]);

line(screen_x[4], screen_y[4], screen_x[5], screen_y[5]);
line(screen_x[5], screen_y[5], screen_x[6], screen_y[6]);
line(screen_x[6], screen_y[6], screen_x[7], screen_y[7]);
line(screen_x[7], screen_y[7], screen_x[4], screen_y[4]);

line(screen_x[0], screen_y[0], screen_x[4], screen_y[4]);
line(screen_x[1], screen_y[1], screen_x[5], screen_y[5]);
line(screen_x[2], screen_y[2], screen_x[6], screen_y[6]);
line(screen_x[3], screen_y[3], screen_x[7], screen_y[7]);
}

init_cube()
{

int i;

//vector 0
obj_x[0] = -1;
obj_y[0] = 1;
obj_z[0] = 1;

//vector 1
obj_x[1] = 1;
obj_y[1] = 1;
obj_z[1] = 1;

//vector 2
obj_x[2] = 1;
obj_y[2] = -1;
obj_z[2] = 1;

//vector 3
obj_x[3] = -1;
obj_y[3] = -1;
obj_z[3] = 1;

//vector 4
obj_x[4] = -1;
obj_y[4] = 1;
obj_z[4] = -1;

//vector 5
obj_x[5] = 1;
obj_y[5] = 1;
obj_z[5] = -1;

//vector 6
obj_x[6] = 1;
obj_y[6] = -1;
obj_z[6] = -1;

//vector 7
obj_x[7] = -1;
obj_y[7] = -1;
obj_z[7] = -1;

for(i=0;i<8;i++)
{world_y[i] = obj_y[i];}

}

text_output(int i, float j)
{
clear();
text(5,20, obj_x[j]);
text(5,35,obj_y[j]);
text(5,50,obj_z[j]);
text(5,70,world_x[j]);
text(5,85,world_y[j]);
text(5,100,world_z[j]);
text(5,120,screen_x[j]);
text(5,135,screen_y[j]);
text(5,155,cosine_table[i]);
text(5,170,sine_table[i]);
text(5,190,i);
text(5,205,j);
}


/*------------------------------------------------------------------------------------------*/

main()
{
int i, j;
int output;
i=0;
//setbrushattr(0, 0, 0);

init_cube();
table_init();
output = gets("set display output flag. 0 for no output, 1 for vectot output");
while(1)
{
if(i>255) i=0; //i couldn't get if(i=256) to work here.
for(j=0;j<8;j++)
{
world_x[j]= new_x(i, obj_z[j], obj_x[j]);
world_z[j]= new_z(i, obj_z[j], obj_x[j]);

screen_x[j] = screencoor_x(world_x[j], world_z[j]);
screen_y[j] = screencoor_y(world_y[j], world_z[j]);

if(output)text_output(i,j);

}
i++;
clearg();
draw_obj();


}
}:?:
MarzAstral
 
Posts: 8
Joined: Mon Sep 23, 2002 4:54 pm
Location: USA

Postby MarzAstral on Thu Aug 05, 2004 11:28 pm

Those 8-balls should be the array sizes. those are arrays that store 8 values.
MarzAstral
 
Posts: 8
Joined: Mon Sep 23, 2002 4:54 pm
Location: USA

Postby FrankG on Fri Aug 06, 2004 11:08 am

<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by MarzAstral</i>
<br /><snip>for some reason the sine and cosine tables have negative values in them and i don't know why.

int i;
for(i=0;i<256;i++)
{
cosine_table[i]=cos(i*6.28/256); // <--- i think the problem lies in these two expressions.
sine_table[i]=sin(i*6.28/256); // <---
}
<hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">
I apologize if these are dumb questions but your trig table build routine -- quoted above -- figures the sines and cosines for a complete circle (i.e. 2*pi radians) in 256 increments. Wouldn't you expect that half of the values in each table would be negative?

I guess another question would be the values of the (int) i*(float) 6.28 / (int) 256 ---- does that result in a float?

Just some ideas,
Frank
FrankG
 
Posts: 210
Joined: Thu Jan 23, 2003 7:58 pm


Return to PocketC for Palm OS KB

Who is online

Users browsing this forum: No registered users and 2 guests

cron