Im working on a system for skeletal animation and each bone's angle is based on its parent. I have to rotate that bone from the end of the parent joint for that angle to be accurate as illustrated in the first part of this illustration:
What I need to do is the second part of the illustration. This is because my drawing API only supports rotating around the center of the bitmap.
Thanks
Combine the rotation with a translation. Rotate the figure about the center, then move it to where it should be.
One option is to introduce extra blank pixels into your bitmap. If you can only rotate around the center of the bitmap, consider what happens if you double the width of your bitmap and then translate the image you want to rotate so that it's flush up against the right.
For example, suppose your image is
+-------+
X image |
+-------+
where the X is the point you want to rotate around. Now, construct this image:
+-------+-------+
| blank X image |
+-------+-------+
If you rotate around the center of this image, notice that you're rotating right on top of the X, which is what you wanted to do in the first place. The resulting rotated image looks like this:
+---+
| b |
| l |
| a |
| n |
| k |
+-X-+
| i |
| m |
| a |
| g |
| e |
+---+
Now, you just extract the bottom half of the image and you've got your original image, rotate 90 degrees around the indicated X point.
Hope this helps!
Related
I have a small problem calculating normals for my heightmap. It has a strange behavior. At the higher and the lower points the normals are fine, but in the middle they seem wrong. They are lighted by a point light.
UNFIXED SOURCE REMOVED
EDIT:
Tried 2 new approaches:
This is per-face-normal. It looks fine but you see the single faces.
Position normal = crossP(vectorize(pOL, pUR), vectorize(pOR, pUL));
I also tried to do it per-vertex this way, but also with a strange output.
This is the suggestion Nico made:
It looks also rather odd. Maybe there is a mistake how I calculate the helping points.
UNFIXED SOURCE REMOVED
EDIT 2:
Definition of my points:
OL,OR,UL,UR are the corner vertices of the plane that is to be drawn.
postVertPosZ1 postVertPosZ2
preVertPosX1 pOL pOR postVertPosX1
preVertPosX2 pUL pUR postVertPosX2
preVertPosZ1 preVertPosZ2
EDIT3:
I solved it now. It was a stupid mistake:
I forgot to multiply the y value of the helping Vertices with the height Multiplier and had to change some values.
It is beautiful now.
There are lots of ways to solve this problem. I haven't encountered yours. I suggest using central differences to estimate partial derivatives of the height field. Then use the cross product to get the normal:
Each vertex normal can be calculated from its four neighbors. You don't need the plane plus its neighbors:
T
L O R
B
O is the vertex for which you want to calculate the normal. The other vertices (top, right, bottom, left) are its neighbors. Then we want to calculate the central differences in the horizontal and vertical direction:
/ 2 \
horizontal = | height(R) - height(L) |
\ 0 /
/ 0 \
vertical = | height(B) - height(T) |
\ 2 /
The normal is the cross product of these tangents:
normal = normalize(cross(vertical, horizontal))
/ / height(L) - height(R) \ \
= normalize | | 2 | |
\ \ height(T) - height(B) / /
Note that these calculations assume that your x-axis is aligned to the right and the z-axis down.
How should I implement sub-windows in my OpenGL viewport? Inside my viewport, I want to reserve some space on the left for labels, and some space around the edges as a border. I've got all the coordinates figured out and everything is displaying properly. My problem is clipping the things in one subwindow that are spilling over into the others. I can't seem to figure out what the OpenGL 3.3, core context way of doing things is. Is it to
use per-vertex clipping?
a scissor test?
a stencil test?
associate a framebuffer with different parts of my window?
Which commands should I be looking at?
Before I spend time writing a full answer, I would like you to confirm that this is what you were describing in your original question:
*---------------------------------------*
| ------------------------------------- |
| | | | |
| | | | |
| | | | |
|C| A | B |C|
| | | | |
| | | | |
| |___|_______________________________| |
*---------------------------------------*
A = Labels
B = Main Window
C = Border
I am trying to implement affine transformation on two images.
First i find the matching pairs in both of the images. One of them is zoomed image and the other is a reference image. The pairs returned me co-efficients as :
|1 0 | | x | | 1 |
A = | | X = | | B = | |
|0 0 | | y | | 221 |
The equation formed is X' = AX + B;
x_co_efficients[2] = (((x_new_Cordinate[2]-x_new_Cordinate[0])*(xCordinate[1]- xCordinate[0])) - ((x_new_Cordinate[1]-x_new_Cordinate[0])*(xCordinate[2] - xCordinate[0])))/
(((xCordinate[1]-xCordinate[0])*(yCordinate[2]-yCordinate[0])) - ((xCordinate[2]-xCordinate[0])*(yCordinate[1]-yCordinate[0])));
x_co_efficients[1] = ((x_new_Cordinate[1]-x_new_Cordinate[0]) - (yCordinate[1]-yCordinate[0])*(x_co_efficients[2]))/(xCordinate[1]-xCordinate[0]);
x_co_efficients[0] = x_new_Cordinate[0] - (((x_co_efficients[1])*(xCordinate[0])) + ((x_co_efficients[2])*(yCordinate[0])));
y_co_efficients[2] = (((y_new_Cordinate[2]-y_new_Cordinate[0])*(xCordinate[1]- xCordinate[0])) - ((y_new_Cordinate[1]-y_new_Cordinate[0])*(xCordinate[2] - xCordinate[0])))/
(((xCordinate[1]-xCordinate[0])*(yCordinate[2]-yCordinate[0])) - ((xCordinate[2]-xCordinate[0])*(yCordinate[1]-yCordinate[0])));
y_co_efficients[1] = ((y_new_Cordinate[1]-y_new_Cordinate[0]) - (yCordinate[1]-yCordinate[0])*(y_co_efficients[2]))/(xCordinate[1]-xCordinate[0]);
y_co_efficients[0] = y_new_Cordinate[0] - (((y_co_efficients[1])*(xCordinate[0])) + ((y_co_efficients[2])*(yCordinate[0])));
These are the equations i am used to finned the co-efficients from using the matching pairs. The equations are working fine for same images, for zooming image it is giving me those co-efficients. Now the problem is i have a 24 bit binary image, i want to implement affine transformation on that image with respect to reference. Now when i try to find the new co-ordinates of that image and change its current value to that co-ordinate I get a very much distorted image. which is should not get otherwise if the transformation is right.
Can Some one please have a look at the equations and also explain a little bit how to implement these equations on the second image.
My code is in C++. Thank you.
My reference image is above.. and my comparison image is
The result i am getting is a distorted image with lines only.
Edit 1
I have now changed the solving method to matrices. Now i am getting the right output but the image i am getting after registration is like this..
Also i have to applied limit of 0 to 320*240 in the new co-ordinates to get the pixel value. Now my result is somewhat like this.
EDIT 2
I have changed the code and m getting this result without any black pixels. I am getting a little tilting.. have removed zoom effect in the given image though.
Your transformation matrix A is problematic. It destroys the y coordinate value and assigns 221 to all y coordinates
You can make the element at (2,2) in A just 1 and problem should be solved.
I am trying to draw the intersection of one blue rectangle and one yellow rectangle
,-------------------,
| |
| Blue |
| ,-------+---------,
| | Green | |
'-----------+-------, Yellow |
|_________________|
using the methods CDC::Polygon and CDC::SetBkMode(TRANSPARENT)
but all I get is this :
,-------------------,
| |
| Blue |
| ,-------+---------,
| | |
'-----------+ Yellow |
|_________________|
Please give me a simple solution sticking with the MFC.
Thanks.
You cannot do this, regardless of whether SetBkMode is TRANSPARENT or OPAQUE since Polygon uses the currently selected brush to fill the polygon's interior. Instead what you should do is this:
Paint one rectangle first, paint the other rectangle next and then calculate the intersection of the two rectangles using CRect::IntersectRect (see http://msdn.microsoft.com/en-us/library/262w7389(v=vs.100).aspx).
If the intersection is non-empty, calculate the resulting "color blend" and create the appropriate brush and, using it, draw a third rectangle using.
For more information on how to blend the colors, check out Algorithm for Additive Color Mixing for RGB Values right here on StackOverflow.
If i have made rectangle then it is possible to add any text inside/onto that, like if there is a rectangle and I want to give a name to it for a case RECTANGLE, Something like this :
| |
| TEXT |
| |
| |
Thanks in advance:)
use a normal rectangle shape and add a decoration to it. A decoration can be places at any position.
see example: Figure Locator
Greetings
Andreas