Advertisement

Erm.. Just read :)

Started by April 15, 2003 04:18 AM
7 comments, last by malpass 21 years, 10 months ago
OK, i''v whipped up a multivariable 3d array graph plotter that all relies on 1 equation. The equation looks like this in the actual code on the program: return (x*(Math.Sin((x*y - x*x + y*y)/y*(Math.PI/180)))); Now, what I want is for the user to type in an equation (Like that, as in with Math.Sin and so on) and then be able to use that in the program, to calculate what they typed in. How can I do this? Oh and also if I have a timer that rotates the graph each millisecond or 2 and redraws the graph, it flickers. I''v tryed double buffering but that doesn''t, how can I prevent this flickering?
How can I do this?

What you are looking for is called a parser.
Here''s a sample search.

I''v tryed double buffering but that doesn''t, how can I prevent this flickering?

If you are sure double-buffering doesn''t work, the solution, if any, will be API-dependent. There is not enough information in your post to conclude.




[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
not enough info? it flickers, simple. When I draw the graph (with GDI+''s DrawLine calls) the output flickers.

Oh and a parser? I made one that did all but brackets I didn''t realise they were actually called something I just made one up, but I was after an easier way.

Any solutions on the flickering?
You''re drawing the line to a bitmap, and then when you''re done all of your line drawing you draw the bitmap, right?

Will
------------------http://www.nentari.com
quote:
Original post by malpass
not enough info? it flickers, simple. When I draw the graph (with GDI+''s DrawLine calls) the output flickers.


He was asking what api you were using. Direct3D, DirectDraw, OpenGL, GDI+?

quote:
Oh and a parser? I made one that did all but brackets I didn''t realise they were actually called something I just made one up, but I was after an easier way.

A working parser isn''t likely to resemble something you just made up. Check the sample search he provided, you might be able to find a library that will do what you want.
Best ever, this code actually compiles the user''s expression into machine code at runtime, and lets you jump into it, so it runs ultra-fast. It''s encapsulated in a nice class, and allows parameters in the expression.

It supports many standard functions, and if you look at the code it should be easy to add your own.

I used this code in a physics demo I wrote some time back which allowed the user to type in a 3d function that defined a heightmap used by the demo.

Expression Parser/Compiler/Evaluator



~BenDilts( void );
Advertisement
that looks nice but i''m using C# not c++
Dude, do some of your own research here... You obviously haven''t tried very hard and you don''t want to to hard; you just want to be given a solution. Unfortunately, it isn''t that simple. I think you should stop being lazy and start googling.
lol, didnt you even read the post, I already have made my own, I just didn''t think that was the correct way to do it...

This topic is closed to new replies.

Advertisement