Rotating problem
BlitzMax Forums/BlitzMax Programming/Rotating problem
| ||
Hi, For my project I need to draw rect but just outline . I made simple function to draw rect Method DrawRectLine(x:Int, y:Int, w:Int, h:Int) DrawLine x, y, x + w, y DrawLine x + w, y, x + w, y + h DrawLine x + w, y + h, x, y + h DrawLine x, y + h, x, y End Method I have problem when I try to rotate that my rect each line rotate separately :) SetRotation(45) DrawRectLine(100, 100, 200, 50) SetRotation(0) Any ideas how to solve this problem Thanks Last edited 2011 |
| ||
Well you could account for the rotation and adjust your lines accordingly, but I think the easiest solution would simply be to calculate the four points of your rectangle yourself so that you can draw without rotation. Store the center of your rectangle, and then treat each of the four corners as vectors from that center point. You can calculate those local positions with simple sin and cos, (x=cos(angle)*radius, y=sin(angle)*radius) and then add on the center of the rectangle to those local coordinates before you draw to get screen coordinates. If you don't know your trigonometry and need more detail, just ask. |
| ||
Thanks for your replay That is ok I just want to be sure that I didn't miss something useful :) That looks like the best solution Thanks again |
| ||
SetHandle(x,y) ? not sure if that would work... |
| ||
@ Afke If your project is to use trigonometry then go for it. Great fun. If your project is to think and draw in X-Y and then rotate, I like OddBall's Module: Oh, I substituted Function for Method. Last edited 2011 Last edited 2011 |
| ||
Thanks Adam , tried that already,didn't work :) EDIT: @John G Thanks for your help, I will look at :) Last edited 2011 |
| ||
if you are trying to frame images you can use this: http://www.blitzmax.com/Community/posts.php?topic=93221#1066645 |
| ||
@John G Thanks, First part of your code do exactly the same as mine ,produce same effect :) |
| ||
@Jesse That is what I want to do .I need it for my editor .When Image is in Select mode :) Thanks |
| ||
@Afke Perhaps I didn't explain very clearly. The first part of the code just replicates what you first proposed, with crude annimation. Same 'undesired' result. The second part requires Oddball's FREE Module to be installed first. http://www.gooeyblob.com/mods/odd2dmodule.zip He somehow modifies the Max2D graphics drivers with additional capabilities for DX7, DX9 and OpenGL. I used OpenGL drivers in the example code above. I've tried all 3 drivers Win/Mac and haven't noticed any glitches or performance penalties. You can build a quite complex X-Y drawing and then rotate the whole lot easily. It's like Push and Pop in OpenGL (which I believe is built into Monkey already). For what I do, the odd2d extensions make the near-perfect BlitzMax even slightly better. Sounds like Jesse offered the solution you were looking for. Cheers. Last edited 2011 |
| ||
Thanks John for your help and time It Looks like great module :) |