PDA

View Full Version : Rotate point sprite given a texture atlas



Apollonio
01-07-2016, 09:21 AM
Hi everyone

given:
- a textured point sprite (a circle) in 3D space with a normal
- a texture atlas with each sprite being a different rotation of that circle along X/Y axes (Z useless). first row all Y rotation, first column all X, and all the other combinations along the sheet.

I'd like to offset the right sprite for the point from the texture atlas given the position of the camera in the world.
I want to use textured sprites instead of quads for achieve maximum performance and given that i'm using VBO all the work must be done in vertex/fragment shader.
I'm bumping into several problems and would like to ask about some hints on this.
:biggrin-new:




(READ THIS ONLY AS AN EXTRA AND IF YOU HAVE TIME)

I write here some of the approaches I've thinked of and tryed.

- build a solidal system of axes to the normal (being the positive Z-axis, 1,0,0 for example). Get the angles between normal and the projection of the camera vector (from camera to the point, all in 3D) in the x-z plane, and y-z plane. These represent my rotation around Y and X axis (not properly, a sort of approximation).
problem -> this system works only on some cases and if you keep looking at the point (obviously). For example if you move near the X-Y plane looking at the point, you will get values not representative of the current rotation.

- given an X-Y-Z plane like up here, where Z is the normal vector, compute in which part of the unit circle the camera vector falls...then just map a sector to a sprite (i don't need many rotations...).
In this case i don't have any idea about how to check in which sector on the sphere the point falls, nor mapping efficiently without an horrible if if if else....

The Little Body
01-24-2016, 03:33 PM
- given an X-Y-Z plane like up here, where Z is the normal vector, compute in which part of the unit circle the camera vector falls...then just map a sector to a sprite (i don't need many rotations...).
In this case i don't have any idea about how to check in which sector on the sphere the point falls, nor mapping efficiently without an horrible if if if else....


Hi, Apollonio

You think about something like the computation of the octant when you write " compute in which part of the unit circle the camera vector falls." ?
(the "how to check in which sector on the sphere the point falls" seem to confirm this)

And/or extend this for to compute the precise point of intersection into this octant ?

Apollonio
02-02-2016, 09:04 AM
Hi there!

Not properly i was thinking about assign a sector of the sphere to a sprite. In other words calculate where the camera position falls respect to the point (being it the center of the sphere).


I have anyway an update to give.
I found a way to make it works as follow:

- use the transformed normal on fragment shader (gl_NormalMatrix * gl_Normal).
- build an axis system around the point using cross products (the point is the origin, Z axis is the transformed normal)
- project the transformed normal on the XZ plane and get the angle (dot) between the projection and the camera 'center of sight' vector (always 0,0,1 in view coordinates)
- do the same on the XY plane.
- now you got 2 angles which can be used to index the spriteSheet.

unluckily i can't upload the spritesheet image right now. :dejection:

this method holds if the point stays at the center of camera...let's say for now this is ok...
anyway i don't think that the spritesheet is correctly made as i still got some problems...

Apollonio
02-05-2016, 02:24 AM
Here's the sprite sheet...i zoomed a part 'cause otherwise is unreadable...
(i think by the way it is incorrent in absolute x-y rotations...some hints on that?)

Apollonio
04-05-2016, 08:34 AM
bump (padding)

AlexAu
04-26-2016, 02:44 PM
I agree with it