Origin and position difference - position

I'm learning the libgdx engine and i got difficulties understanding the difference of .setOrigin and .setPosition . Take the demo libgdx creates. What is the difference if i put 1f,1f on origin and what on position of the texture this demo uses?

The Origin is used for Scaling and Rotating transforms. For example, if you put the origin at the Center of your sprite (width/2, height/2). When you rotate it, it will rotate around its center.
The position is the bottom-left corner of your sprite in world coordinates.
What is the difference if i put 1f,1f on origin and what on position of the texture this demo uses?
On origin it won't make any difference if you don't rotate or scale the sprite. On position, it will change where the sprite is drawn.

Related

What is the Godot way to define (and refer) custom rectangle areas?

I'm coming from Phaser + Tiled world, where, if I need some rectangle area in game world (like Player's area, spawning area, and so on) I can just draw rectangle in Tiled and then get it coordinates from Phaser.js and use as I need. And I seem to stuck to do similar things in Godot.
For some of tasks I can use Area2D with rectangle inside and collision events. But it is not always enough.
How can I just define rectangle on screen, and get its coordinates? For Sprite object and for Node2D I cannot get bounding rectangle. I can use Area2D + Rectangle and refer to rectangle's 'extent' property to get width/height, but that seems to be overhead for me - Area2D is used in collision detection.
What can I do in general? And what could be done in Godot for following scenarios?
Camera limits. I have Sprite with background gradient which I scale to needed world size, and I'd like to set camera limits on that Sprite's width/height.
Hero movement limits. Half of world is not accessible for player, so any move to x > MIDDLE shall be denied. I can just setup constant MIDDLE in the code, but I'd like to draw allowed area as rectangle and refer to it coordinates.
Spawn area. Mark some place of world (that could be just point, not rectangle) where new objects shall be created by code.
You could use the Rect2 class in a script to define custom rectangles. You can then use it to check whether it contains a Vector2 or another Rect2.

Graphics clipping, why not clip pixels

I have a question about graphics clipping.
The question is: why do we need line clipping or polygon clipping?
Can we just rasterize everything then clip the pixels out of the
clipping window?
Thanks
You could do that, but as people in the comments have said, it is slower.
You can clip the far, left/right and top/bottom planes in screen space.
The problem is if a 3D object is partially behind the camera. You cannot "rasterize everything" behind a camera because typical 3D projection equations that divide by z do not make sense behind the camera - your points/vertices will be inverted/upside-down. If you have color/texture mapping it'll look weird. So at the very least your program will have to clip by the near plane and interpolate all color/texture data to the newly clipped points.
An exception is if you're doing raytracing/raycasting - rays do not go behind the camera so it works.

How to determine the radius of a circle from the scale of the sprite?

I am making this game where a sprite of a circle( origin set at the center of the sprite) is being up-scaled and rotated simultaneously. What I need to determine is the change in the radius of the circle in relation to scaling.How do I go about doing that? What exactly does scaling do? I mean what does 2x scale mean? does it mean my sprite has twice the area than previous? Btw , I am using LibGDX.
I figured it out myself.The problem was that the bounding rectangle of a sprite changes in size as the sprite is being rotated.So the raidous of the circle can not be determined using the with of the rectangle at that time. What I found was that the width of the bounding rectangle is the product of the scale and the initial width .So I can calculate what the width would be at any instance from that even if the sprite is rotating. And I get the radius from that.

Getting distorted svg circles after a lot of zooming in

I am using raphael to create svg circles. I am also doing zoom and pan using setViewBox as suggested in http://jsfiddle.net/9zu4U/10/ . Actually my problem is like I create a circle on screen and clicking on that circle creates 20 smaller circles inside the bigger circle. So I zoom in and I click on any of the smaller circles. It creates 20 circle inside that circle. And I zoom in and so on. But after 6-7 levels it gives me distorted circles and hexagons. What could be the reason of this? It doesn't happen in Mozilla.
I tried creating a very big paper and a very big circle initially and displaying it zoomed out so it fits the screen. Just to ensure that the radius of smallest circle don't go in decimal values.
EDIT : example jsfiddle.net/LbcPd/3 .

Terrain tile scale in case of tilted camera

I am working on 3d terrain visualization tool right now. Surface is logically covered with square tiles. This tiling could be visualized as follows:
Suppose I want to draw a picture on these tiles. The level of detail for a picture is required to be selected according to the current camera scale which is calculated for each tile individually.
In case of vertical camera (no tilt, i.e. camera looks perpendicularly on the ground) all tiles have the same scale which is camera focal length divided on camera height above the ground.
Following picture depicts the situation:
where red triangle is camera which has no tilt, BG is camera height above the ground and EG is focal length, then scale = AC/DF = BG/EG
But if camera has tilt (i.e. pitch angle isn't 0) then scale is changed from tile to tile (even from point to point).
So I wonder if there any kind method to produce reasonable scale for each tile in that case ?
There may be (there almost surely is) a more straightforward solution, but what you could do is regular world to screen coordinate conversion.
You just take the coordinates of bounding points of the tile and calculate to which pixels on the screen these will project (you of course get floating point precision). From this, I believe you can calculate the "scale" you are mentioning.
This is applicable to any point or set of points in the world space.
Here is tutorial on how to do this "by hand".
If you are rendering the tiles with OpenGL or DirectX, you can do this much easier.

Resources