Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

2d Square Rotations

Name: Anonymous 2009-07-17 0:13

To do this I know you need to use trig functions, but I cant seem to get it right. Anyone know of some source code that does this properly?

Name: Anonymous 2009-07-17 0:39

glRotate(angle, 0, 0, 1)

Name: Anonymous 2009-07-17 1:01

>>2
lol I guess that makes things easy.

Name: Anonymous 2009-07-17 1:23

cosine and sine, look into them

Name: Anonymous 2009-07-17 1:25

>>4
I accidentally the whole unit circle

Name: Anonymous 2009-07-17 1:27

Name: Anonymous 2009-07-17 1:46

>>6
There we go, this is useful!

Name: Anonymous 2009-07-17 5:16

>>2
This function is deprecated. Please upgrade your code to be 3.1 conformant.

Name: Anonymous 2009-07-17 11:24

>>8
Fine, ill just defaecate on your function too.

Name: Anonymous 2009-07-17 13:57

>>8
But hardly any common hardware supports the newest OpenGL standards.

Name: Anonymous 2009-07-17 14:01

>>10
common hardware
newest standards
HURRRRRRRRRRRRRR

Name: Anonymous 2009-07-17 14:30

Name: Anonymous 2009-07-18 13:25

I am having major problems getting this to work.

First of all, I sort of understand the general idea behind matrices, but I'm a little lost trying to implement them.

Second, I'm not sure this is even going to do what I want it to do.

Right now, the way my program is working, If you try and rotate the square, it just kinda disappears.

I want my program to
A: Display a square anywhere on the screen.
B: Be able to rotate that square as if a tack were placed in it's center.
C: Be able to change directions of the rotation whenever.

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !frozEn/KIg 2009-07-18 13:42

>>13 Could you post the code with the square? Since you post anonymously theres no harm.



______________________________________________
http://xs135.xs.to/xs135/09042/av922.jpg
The fact that we are I don't know how many millions of people, yet communication, complete communication, is completely impossible between two of those people, is to me one of the biggest tragic themes in the world.

Name: Anonymous 2009-07-18 13:47

>>13
I tried doing this in text-mode Pascal once. I suggest:

- Define a vertex based on angle and magnitude from centre of square (the angle is (say) 0 at due east and increases anticlockwise)
- Vertex coordinates are now x = sin(angle) * magnitude + centre_x and y = cos(angle) * magnitude + centre_y or something like that
- Draw the square using various line interpolation and fill routines. Change angle every frame for rotation.

I don't know what you're using (Python + pygame? C? SDL with blitting? Tk canvas?) so these are just rough guidelines and probably completely wrong, but whatever.

Name: Anonymous 2009-07-18 14:34

Its really retarded, trust me I know.

if(left)
            {
                 try {
                        Thread.sleep(100);
                     }
                    catch (Exception e) {
                       
                     }
               
                    System.out.println("" + dx);
                dx = dx*Math.cos(9) - dy*Math.sin(9);
                dy = dy*Math.cos(9) + dx*Math.sin(9);
            }
            if(right)
            {
                 try {
                        Thread.sleep(100);
                     }
                    catch (Exception e) {
                       
                     }
               
               
                dx = dx*Math.cos(9) + dy*Math.sin(9);
                dy = dy*Math.cos(9) - dx*Math.sin(9);
            }

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !frozEn/KIg 2009-07-18 14:37

Maybe you should try http://www.morrowland.com/apron/tutorials/gl/gl_rotating_cube.php



___________________________________
http://xs135.xs.to/xs135/09042/av922.jpg
A strange neurosis, evidently contagious, an epidemic mass hysteria. In two weeks, it spread all over town.

Name: Anonymous 2009-07-18 15:45

>>16
I don't need to trust you, I can see it's retarded. Also, math functions are in radians. Also, make a velocity variable instead of that massive if clause.

Name: Anonymous 2009-07-18 16:13

>>16
try {
    ....
}
catch (Exception e) { 
}

I WISH I COULD THINK YOU DEAD FOR THIS KIND OF EXCEPTION HANDLING STRATEGY!

Name: Anonymous 2009-07-18 17:31

>>16
This post made me laugh so hard that I actually want to bump this thread. Thank you.

Name: Anonymous 2009-07-18 17:51

>>19
Don't tell me you think UNWIND-PROTECT is the worst thing ever?

Name: Anonymous 2009-07-18 17:52

I don't get it

Name: Anonymous 2009-07-18 18:28

dynamic-wind

Name: Anonymous 2009-07-18 20:34

>>21
I think he meant that >>16-kun doesn't actually handle the exception he is catching.

I would, however, like to hear more about >>21 and >>23; I assume it has to do with LISP and manipulating the call stack?

Name: Anonymous 2009-07-18 21:10

>>24
UNWIND-PROTECT is a Common Lisp Special Operator, it executes a form and guarantees that no matter what happens in that form, it will execute some cleanup forms. It is pretty much a try{...code...}finally{...cleanup...} , that means that it handles cleanup code, but exception is passed up.

In this example:

(catch 'test
  (unwind-protect
       (throw 'test 'actual-result)
    (princ "always executed"))
  (princ "missed"))

It will print "always execute" to *standard-output* and the result of the form will be 'actual-result, (princ "missed") won't be executed. (The difference between try{}catch{} and try{}finally{} - is that the exception is passed back up after finally, and the stack keeps unwinding, while try{}catch{} will ignore whatever exception happens.)

Unrelated directly to UNWIND-PROTECT:
Common LISP has a very good condition system as well, which allows separating the code for signaling an error, code for handling an error(and within what context), and code which decides the actual handling strategy. This allows one to handle errors as locally as possible, but with global strategies(such as decided by a top level form).It can avoid unwinding the stack, just so it could get to a top level catch {} form, compared to languages like Java/C# or C++. (This is not very relevant, but similar exception handling strategies can be implemented via SEH/VEH in Windows and signals in *NIX, but it's not something provided in such a convenient way by the actual language).

dynamic-wind is a SCHEME construct, which will run a form, and if the form exits through a continuation, it will run the post-thunk (for example for cleanup), if some code returns in the form through a continuation, it will run the pre-thunk. This is necessary as continuations are first class objects in scheme and they are reusable ( This however has very high costs, such as stack copying, and increasing the complexity of compilers. Limited forms of continuations can be implemented in Common Lisp through a code walker. Limitations tend to be similar to things like: In which forms you can use pseudo-call/cc). UNWIND-PROTECT can't be easily implemented in scheme since continuations are first class objects, and it gets really hairy when it comes to guranteeing that the code will be executed and it will be executed only once within one context, since continuations are reusable. dynamic-wind provides a way to handle this which is compatible with first class continuations.

Name: Anonymous 2009-07-18 21:11

Forgot my code tags:

(catch 'test
  (unwind-protect
       (throw 'test 'actual-result)
    (princ "always executed"))
  (princ "missed"))

Don't change these.
Name: Email:
Entire Thread Thread List