SetOrigin()

BlitzMax Forums/BlitzMax Programming/SetOrigin()

TaskMaster(Posted 2007) [#1]
I started using this today and I think it is backwards.

If I use SetOrigin, shouldn't that be like changing the upper left corner of the drawing location?

For example, if I have an object that stays in the middle of the screen (400,300) and I want the world to move underneath that object, I would use SetOrigin.

My object moves 10 pixels to the right, so the Origin should now be (10,0) instead of (0,0). But, BlitzMax ADDS the Origin to all drawing commands, it should subtract it. If the center of my screen is (400,300), I tell my object it is now at (410,300) because it moves 10 pixels to the right, shouldn't BlitzMax subtract the (10,0) so that my object still gets drawn at (400,300). Currently, I have to do a SetOrigin(-10,0) to make it right.

Seems to me that this is backwards, but maybe I am looking at it wrong?


jhans0n(Posted 2007) [#2]
SetOrigin is like setting the top left corner of the drawing area. Normally that top corner is 0,0. So if you set the origin to 10,0, everything is shifted to the right by 10 pixels. If you set it to -10,0, everything is shifted to the left by 10 pixels.


TaskMaster(Posted 2007) [#3]
Yes, that is how it works, it just seems backwards to me.

If I set the Origin to (10,0), then it seem to me that something drawn at (0,0) ought to be off the screen to the left by 10 pixels. But, in actuality, it gets drawn 10 pixels to the right of the edge of the screen.

Let me try to trace this:

Start:
My Character (400,300) - Center on a 800x600 screen.
Origin (0,0) - Top Left Corner
My character is 400 pixels from the left edge...

My Character walks 50 pixels to the right:
My Character (450,300)
Origin (50,0)
My Character is still 400 pixels from the top left edge...

This is what I would expect, but if I want BlitzMax to draw my character at the center all of the time, then I need to set the Origin to (-50,0) to get it to draw my (450,0) character at the center, because BlitzMax ADDS the Origin.

It may be working as intended, it just seems backwards to me. Looking at it logically.


tonyg(Posted 2007) [#4]
Don't you just draw your character with setorigin 0,0 each time and coords graphicswidth()/2 and graphicsheight()/2?


TomToad(Posted 2007) [#5]
The origin is just another way of saying coordinates 0,0. When you use SetOrigin, you are telling BlitzMAX how many pixels to move the origin. So if I do SetOrigin(100,150), that means set the origin (coordinates 0,0) 100 pixels right and 150 pixels down on the screen.
Now anything drawn at 10,10 will actually be drawn 110 pixels right and 160 pixels down.




TaskMaster(Posted 2007) [#6]
Yeah, I know how it works, just seems backwards to me to how I though it would work when I first started to implement it.

@tonyg - What I am attempting to do is put everything in world coords, with the player at the center. When the player moves, I just update the Origin and let the player move about freely. It is a space flight game, so there is no restrictions on movement. There might be asteroids at coords (3000,3000) and a space station at (0,0). And a nebulae at (-2200, 4500).

Instead of trying to change coords on everything, I am just figuring the player movement first, then updating the SetOrigin(). Then everything else just moves as it would, not worrying about where the player moved to.

Does this make sense? This way, an asteroid at (500,500) that isn't moving will just always be at (500,500). No worrying about changing it's coords because the player moved.

This is working fine, I am just doing a SetOrigin(-ScreenX, -ScreenY). ScreenX and ScreenY are the coords of the top left corner. Set the SetOrigin() to negative so the system draws them in the right spot.


Floyd(Posted 2007) [#7]
This sort of conflict in "point of view" happens all the time. You may think of moving the graphics on a fixed coordinate system or moving the coordinate system over a fixed drawing. There is no "correct" answer. You just have to adopt one of them as the standard.

The same thing is visible on this page. What happens when you drag the slider on the right side of the window? The result is that you drag the window over a fixed page. Many people think this is wrong when they first experience it. They think the slider should be dragging the page. After all it is the page that moves on screen and the window that stays fixed. But the page moves the opposite direction from the slider.


H&K(Posted 2007) [#8]
Or when you press "up" on the joy stick, and the camera points downwards


Czar Flavius(Posted 2007) [#9]
I don't get what you mean about the window Floyd?


Brucey(Posted 2007) [#10]
You drag the scrollbar "down" to move the page "up"...


H&K(Posted 2007) [#11]
When you move the drag bar, you arent dragging "The document" which you would intuitively be doing in real life. You are draging your eyes/veiw