Sign in to follow this  

sin and cos in Symbian? - now problem with e32math.h

This topic is 4659 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am wondering if it is possible for me to use sin and cos in Symbian (Nokia Series 60)? basically I want to convert this (from nehe tutorial):

   if (key == GLUT_KEY_UP) {
	
	xpos -= (float)sin(heading*piover180) * 0.35f;
	zpos -= (float)cos(heading*piover180) * 0.35f;
   }
   if (key == GLUT_KEY_DOWN) {

	xpos += (float)sin(heading*piover180) * 0.35f;
	zpos += (float)cos(heading*piover180) * 0.35f;
   }
into OpenGL ES code. Any help would be muchly appreciated! [Edited by - Miranda on March 10, 2005 7:27:31 PM]

Share this post


Link to post
Share on other sites
Regardless of whether symbian has sin and cos you are probably best to use a sin/cos lookup table.

http://www.idevgames.com/forum/showthread.php?s=89ba7222b52a397c82aa10b391276676&p=67923#post67923
http://wuarchive.wustl.edu/aminet/dev/asm/SineWriter.readme

This will enhance speed. The links ive provided above should give you all the information you need to know about creating and using the lookup tables.

Share this post


Link to post
Share on other sites
Quote:
Original post by kooktroop
Regardless of whether symbian has sin and cos you are probably best to use a sin/cos lookup table.

http://www.idevgames.com/forum/showthread.php?s=89ba7222b52a397c82aa10b391276676&p=67923#post67923
http://wuarchive.wustl.edu/aminet/dev/asm/SineWriter.readme

This will enhance speed. The links ive provided above should give you all the information you need to know about creating and using the lookup tables.


um....a lookup table...on a phone? that just seems like a waste of memory to me. My understanding is that phone apps/games have a lot harder time with their memory footprint then they do with their speed. Plus it is premature at best to implement a sin/cos lookup table until you know for certain that sin/cos functions are actually slowing down your app. You would know this by writing the app first normally then profiling it to identify the bottlenecks.

at any rate, OpenGL ES is just a graphics API. you don't write an application in OpenGL ES, you would write it in C or C++ or whatever _using_ the OpenGL ES api. so if the compiler you use doesn't barf on the sin/cos syntax when you compile the phone app you're fine. I think it would be crazy if the phones that supported an advanced graphics API didn't also support basic trigonometry.

-me

Share this post


Link to post
Share on other sites
The only way I have found to use the sin and cos functions in ES is to use the math.h library in vc7. This compiles and runs on the emaulator, but does strange things with the sin and cos calculations. I have a feeling it wouldn't work at all on an actual phone...

Any other suggestions?

Share this post


Link to post
Share on other sites
Quote:
Original post by Miranda
The only way I have found to use the sin and cos functions in ES is to use the math.h library in vc7. This compiles and runs on the emaulator, but does strange things with the sin and cos calculations. I have a feeling it wouldn't work at all on an actual phone...

Any other suggestions?


I've made my own sine/cosine functions for my old phone (3510i - J2ME/MIDP1) with a lookup. I set the range from 0-255 degrees and used signed bytes in the range -128..127 (so sin[63]=127). The only stuff on the phone was the 0..63 range, which was then extended by copying to the next quarter then inverting and copying to the last half.

I know nothing about the Series 60 or Symbian, but if my old 3510i could pull off a simple 3D engine I wrote on it with a fairly decent framerate with only a sine lookup table and some elementry fixed-point maths, I'm sure it shouldn't be a problem on a newer phone.

The code ran like this:

int startTrig[] = {0,3,6,9,12,15,18,21,24,28,31,34,37,40,43,46,48,51,54,57,60,63,65,68,71,73,76,78,81,83,85,88,90,92,94,96,98,100,102,104,106,108,109,111,112,114,115,117,118,119,120,121,122,123,124,124,125,126,126,127,127,127,127,127};
int fullTrig[] = new int[256];
// Expand the "full trig" table.
for (int i=0; i<64; ++i) {
fullTrig[i] = startTrig[i];
fullTrig[i+64] = startTrig[63-i];
fullTrig[i+128] = -startTrig[i];
fullTrig[i+192] = -startTrig[63-i];
}

Share this post


Link to post
Share on other sites
"um....a lookup table...on a phone?"

if a phone supports opengl es, it is unlikely that one will bump into memory issues because of a lookup table which should not be larger than 4k. there are other more memory-hungry in a 3d app, like textures and meshes.

in any case, you may probably want to lookup a taylor series approximation of sine or, maybe better, use the cordic algorithm.

Share this post


Link to post
Share on other sites
Lookup tables for sin cos, sqrt and even 1/x (and fixed point of cause) are the only way to develop for Symbian. Most of Symbian phones are terribly slow with floats, due to luck of fp coprocessor. Also all symbian phones have more than 1 mb memory (more than 3 mb actually for all but Nokia 7650), so lookup table memory footprint is negligible

Share this post


Link to post
Share on other sites
What about the e32math.h include? It includes a Sin and Cos calculation using TReal arguments.

At the moment I am trying this:

TReal result;
TInt matherror;

.....

case EStdKeyUpArrow:
matherror = Math::Sin(result, (iAppContainer->iGame01->heading*piover180 * 0.35));
iAppContainer->iGame01->xpos -= result;

matherror = Math::Cos(result, (iAppContainer->iGame01->heading*piover180 * 0.35));
iAppContainer->iGame01->xpos -= result;




It is compiling, but not working, but I suspect the problem could be elsewhere in my code.

I wish i was better at Maths....

[Edited by - Miranda on March 9, 2005 7:14:19 PM]

Share this post


Link to post
Share on other sites

This topic is 4659 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this