A good advice for the future: The size in bytes occupied by one row of pixels in memory is called stride. Its important that in bitmaps stride is always a multiple of 4 bytes. In your cases this condition is true in all cases regardless of the bitmap width because 1 pixel occupies 4 bytes. But for example in a 8 bit bitmap (256 colors) with width==3 the stride would be 4 bytes regardless of the actual size being 3 bytes, there would go 1 byte extra padding.
I have designed a digital controller in matlab. The continuos s domain controller is as follows:
1.16e006 s^2 + 6.287e006 s + 2.436e006
s^2 + 10 s
The discretised z domain version (with a sampling rate of 100Hz) is as follows:
1.16e006 z^2 - 2.26e006 z + 1.1e006
z^2 - 1.905 z + 0.9048
Now i have managed to program this in C++ and it "sort of" works. However the code is by no means optimal and therefore does not execute as quickly as it should. The code basically looks like this:
float dencoeff ;
numcoeff = 1160000;
numcoeff = -2260000;
numcoeff = 1100000;
dencoeff = 1;
dencoeff = -1.905;
dencoeff = 0.9048;
SpeedError = MeasuredGeneratorSpeed - SpeedDemand;
xprevious = SpeedError; //current input value
y = xprevious*numcoeff; // get it started
y += ((xprevious*numcoeff)+(xprevious*numcoeff)-(yprevious*dencoeff)-(yprevious*dencoeff));
xprevious = xprevious; //Shift the values down
xprevious = xprevious;
yprevious = yprevious;
yprevious = y; // Current Output
Where xprevious,yprevious are arrays that i define earlier in the program. They are used to store the previous input and output values. X is the input and Y is the output. The numbers stored in the numcoeff and dencoeff arrays correspond to the coefficients in the z domain transfer function shown at the top. Is there a faster way to do this calculation in c++, perhaps by using a circular queue!!??. Unfortunately my programming knowledge is not great(I'm a Matlab guy). If there is a better way to do it that would speed up the calculation perhaps someone could give me an eample of how to do it. By the way all the variables and arrays are floating point. Any help or advice would be much appreciated.
that looks pretty straightforward. i doubt a circular buffer is going to give you much improvement - you're just copying some floats around, after all. no matter where they reside or how you abstract your data structure (array, circ buffer, etc), you're still copying floats.
you could probably speed it up a bit using vector processing - execute those four multiplications in one call. you could do the addition/subtraction in one call, too. search here for "SIMD" or "SSE". though that stuff might look a little scary, if you're coming from MatLab...
I guess I know what you mean: You press down the pan mouse button while the cursor is over the view and then you pan by moving the mouse cursor until you release the pan mouse button. This panning basically scrolls the visible portion of the stuff you can see in your view. There is no API to do that, you have to implement it by yourself by handling primitive mouse events like mouse button down, mouse move, and mouse button up events. Custom implementation makes sense because its totally dependent on the program which parameters should be modified by the panning operation.
In a 2D pdf viewer the program stores some position data about which part of the pdf should be drawn to the view. This position is changed when you are panning. In a 3D CAD program there is a 3d world in which you can find an active camera as well with a position and rotation parameter (and also with horizontal and vertical fov). This camera is used by the rednerer to decide which part of the world should be rendered, the camera is like an eye and you see in the view what this eye looks at in the 3d world. This camera has an up and right direction that defines a plane. When you pan with your mouse you basically calculate a 2D offset from the mouse movement and you add this 2D offset to the camera position on the plane that is defined by the up and right vectors of the camera rotation (maybe not right but left if you are using left handed coordinate system...). Even if you are not good at 3D, the answer to your question is: Those pan functions are implemented by those programs, its custom code in them and not some operating system provided api function calls.
How to implement panning: When panning starts (mouse button down) you store the actual pan-start position of the mouse cursor, and also the position value (the 3d cam pos, or the 2d pos in the pdf file) in your program to some variables that wont change during panning. When a mouse move event comes you always calculate the delta between the pan-start mouse pos and the current moved mouse cursor pos, and you use this 2D offset to calculate the pan offset in your world (you can leave it as it is, or any simple transform can do the job, for example multiplying it with something to set panning speed...). When you have your pan offset you add the resulting pan-offset to the stored pan-start position and set the result as the current position.
You have to do exactly the same. You handle the mouse events, and depending on the offset of the mouse move you change an internal variable in your program. In my example program the internal variable to change was the position of the window, but it could be anything else, for example the offset in your picture or pdf file for drawing on the client area of your window. All you have to do is using/changing something else, not the window position, for example the position where you draw your picture on the client area.
Last Visit: 31-Dec-99 19:00 Last Update: 31-Jan-15 9:47