leonardo
leonardo
Reputation Top 1%
leonardo
7 Snippets  (128th place)
Published
1 Channel
Created
10 Channels
Following
386 points  (80th place)
Reputation
Junior Code Generator
Serious Code Generator
Senior Code Generator
Junior Publisher
Serious Publisher
Junior Trend Maker
Junior Popular Coder
Serious Popular Coder
Junior Autobiographer
Serious Autobiographer
Junior Famous Coder
Serious Famous Coder

Recent Snippets See all snippets by leonardo

public by leonardo  3086  0  3  0

CHEATSHEET - VIDEO

+-------------------------------------------------------+
+ Codecs & Video Formats 								+
+-------------------------------------------------------+

YUV

Y' = luma component (' = gamma compression) (electronic brightness)
Y  = luminance (perceptual brightness)

U and V are blue–luminance and red–luminance differences

YPbPr for analog component video (digital version =  YCbCr)

---

A MPEG file has the frame rate listed as a number from 1 to 15 inside the file itself:

1 = 24000/1001 (23.976...)
2 = 24
3 = 25
4 = 30000/1001 (29.97...)
5 = 30
6 = 50
7 = 60000/1001 (59.94)
8 = 60
9 thru 15 = reserved

And in an AVI file the frame rate is given as two numbers, a numerator and a denominator. Each can be anywhere from 1 to ~4 billion. So the frame rate can be anwhere from 1/4,000,000,000 fps, to 4,000,000,000/1 fps.

Different programs may use different pairs to represent the same frame rate. For example, 24000/1001 or 240000/10010 are exactly the same rate. But some will use 23976/1000 which is slightly different. 

Video Formats:

Advanced Video Codec
Windows Media Video 9 (standardizzato come VC-1)
MPEG-2
MPEG-4 AVC


Conversione cinema to digital domestic video:

Cinema 24p to PAL (25, 50i)
24p -> 25 (dvd) (audio pitch +4%)
24p -> ogni dodici fotogrammi introduce un semiquadro aggiuntivo nel segnale televisivo (50 int.) (no audio distortion)

Cinema 24p to NTSC (29,97, 60i)
24p > 2:3 pulldown (o 3:2 pulldown) -> STEP 1 -0.1% (to 23,976) STEP 2 23.976/29.97 = 4/5
Questo procedimento crea un piccolo errore nel segnale video se confrontato con il filmato originale. Questo è il motivo per cui i film in NTSC visti su apparecchi domestici ordinari possono presentare discontinuità e poca fluidità nei movimenti rispetto alla proiezione cinematografica. Questo fenomeno (chiamato judder) è particolarmente visibile sui movimenti di macchina lenti.

Tecnica del Telecinema Inverso 
Consiste nel rimuovere il pulldown dalle sorgenti video interlacciate, ricostruendo i 24 fotogrammi al secondo originali


High Definition Formats:
576i50
1080i50
480i60
1080i60

480p60
720p60
1080p24


+-------------------------------------------------------+
+ XBMC Video Information 								+
+-------------------------------------------------------+

O 		display stats
es.
D(Audio: ac3, 48000 hz, 6 channels, s16) P(aq:24%, kB/s: 437.28)
D(Video: h265, yuv420P, 1920x1080) P(vq:99%, dc:ff-h264_vdpau, MB/s:41:12. drop:5, pc:4)
C( AS: 0.000, A/V:-0.167, edl:-, dcpu: 3% acpu: 1% vcpu: 2%)
W( fps:23.95 CPU0: 9.5% CPU1: 6.7%)

LEGENDA
D[emux info (audio)](Audio: [codec], [samplerate], [channel count], [sample size]) P[layer info(audio)](aq:[decoded audio frame queue usage], kB/s: [decoded audio bitrate])
D[emux info (audio)](Video: [codec], [pixel format], [resolution]) P[layer info (video)](vq:[decoded video frame queue usage], dc:[codec in use], MB/s:[decoded video bitrate]. drop:[dropped frame count], pc:[pattern correction (3:2 pull, etc)])
C[general info (dunno WTF "C" stands for, probably an elupusism)]( AS: [audio sync delay], A/V:[sync error], edl:[edit decision list info], dcpu: [demux cpu usage] acpu: [audio decode cpu usage] vcpu: [video decode cpu usage])
W[indow? (who cares, this stuff is obvious)]( fps:[render framerate] CPU0: [first scheduling unit usage] CPU1: [...]) 
;

public by leonardo  3917  22  5  -1

CHEATSHEET - LibGdx

LIBGDX CHEATSHEET

Batch
- draw texture regions on screen
- operate in screen coordinates (x right, y upward, origin lower left corner)
- you can provide your own transformation and projection matrices

Typical Flow

OrthographicCamera camera;
SpriteBatch batch;
Texture texture;
Sprite sprite;


INIT>
camera = new OrthographicCamera(1280, 720);
batch = new SpriteBatch();
texture = new Texture(Gdx.files.internal("data/Toronto2048wide.jpg"));
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
sprite = new Sprite(texture);
sprite.setOrigin(0,0);

RENDER>
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(camera.combined);
batch.begin();
sprite.draw(batch);
batch.end();

;

public by leonardo  2916  1  5  1

SNIPPET - Box2d_LibGdx_Integration

/*
<SNIPPET>
	<TAGS = "JAVA,LIBGDX,BOX2D" />
	<NAME="Box2d_LibGdx_Integration" />
	<DESCR>Codice per integrare una texture region con un oggetto Box2D</DESCR>
</SNIPPET>
*/

public TextureWrapper{
     TextureRegion region;
     int width;
     int height;
     Vector2 position;
     float scaleX;
     float scaleY;
     float originX;
     float originY;
     float rotation;
     public TextureWrapper(TextureRegion region,Vector2 pos){
          this.position=pos;
          SetTextureRegion(region);
     } 
     public void SetTextureRegion(TextureRegion region){
          this.region=region;
          width=region.getRegionWidth();
          height=region.getRegionHeight();
          originX=width/2;
          originY=height/2;
          scaleX=1;
          scaleY=1;
     }
     public int GetWidth(){
        return width;
     } 
     public int GetHeight(){
          return height;
     } 

     public void SetPosition(float x,float y){
          position.set(x,y);
     } 
     public void SetRotation(float r){
          rotation=r;
     } 

     public void Draw(SpriteBatch sp){
          sp.draw(region,position.x-width/2, position.y-height/2,
           originX, originY, width, height,
          scaleX, scaleY, rotation);
     }
     ....
}



public class BoxUserData{
        int collisionGroup;
        int boxId;
        public BoxUserData(int boxid,int collisiongroup){
                  Set(boxid,collisiongroup);
        }
        public void Set(int boxid,int collisiongroup){
                  this.boxId=boxid;
                  this.collisionGroup=collisiongroup;
        }
        public int GetBoxId(){
               return this.boxId;
        }
        public int GetCollisionGroup{ 
                return this.collisionGroup;
        }

}
;

public by leonardo  2691  2  6  0

SNIPPET - Box2d_Java

Codice Box2D per creare una simulazione fisica con oggetti fisici
/*
<SNIPPET>
	<TAGS="JAVA,LIBGDX,BOX2D" />
	<NAME="Box2d_Java" />
	<DESCR>Codice Box2D per creare una simulazione fisica con oggetti fisici</DESCR>
</SNIPPET>
*/

// Codice Generico Box2D (only box2d debug mode is visible)

// 100 pixels <-> 1 meter
static final float WORLD_TO_BOX=0.01f; 
static final float BOX_WORLD_TO=100f;
float ConvertToBox(float x){
    return x*WORLD_TO_BOX;
}

// Step 1 - Create World
World world=new World(new Vector2(0,-20),true) // World(Vector2 gravity, boolean doSleep) // com.badlogic.gdx.math

// Step 2 - Create Body
public void CreateBody(World world,Vector2 pos,float angle){
    BodyDef bodyDef = new BodyDef(); 
    bodyDef.type = bodyType; // The body type: static, kinematic, or dynamic
    bodyDef.position.set(ConvertToBox(pos.x),ConvertToBox(pos.y)); // The world position of the body.
    bodyDef.angle=angle; // The world angle of the body in radians.
    body = world.createBody(bodyDef);
}

// Step 3 - Create Fixture/Shape
private void MakeRectFixture(float width,float height,BodyDef.BodyType bodyType,
     float density,float restitution, Vector2 pos,float angle){
     PolygonShape bodyShape = new PolygonShape();

     float w=ConvertToBox(width/2f);
     float h=ConvertToBox(height/2f);
     bodyShape.setAsBox(w,h);

     FixtureDef fixtureDef=new FixtureDef();
     fixtureDef.density=density; // The density, usually in kg/m^2.
     fixtureDef.restitution=restitution; // The restitution (elasticity) usually in the range [0,1].
     fixtureDef.shape=bodyShape;
     /*
     com.badlogic.gdx.physics.box2d.Shape
		com.badlogic.gdx.physics.box2d.PolygonShape {ChainShape, CircleShape, EdgeShape, PolygonShape}
			PolygonShape (->setAsBox(float hx, float hy) Build vertices to represent an axis-aligned box.)
     */

     body.createFixture(fixtureDef);
     bodyShape.dispose(); // lo puoi fare perchè la shape è clonata quando viene assegnata alla fixture
 }

private void MakeCircleFixture(float radius,BodyDef.BodyType bodyType,
     float density,float restitution, Vector2 pos,float angle){

     FixtureDef fixtureDef=new FixtureDef();
     fixtureDef.density=density;
     fixtureDef.restitution=restitution;
     fixtureDef.shape=new CircleShape();
     fixtureDef.shape.setRadius(BoxObjectManager.ConvertToBox(radius));

     body.createFixture(fixtureDef);
     fixtureDef.shape.dispose();
 }

// Step 4 - World Update Fixed TimeStep
static final float BOX_STEP=1/120f;
static final int  BOX_VELOCITY_ITERATIONS=8;
static final int BOX_POSITION_ITERATIONS=3;
float accumulator;

public void Update(float dt){
   accumulator+=dt;
    while(accumulator>BOX_STEP){
      world.step(BOX_STEP,BOX_VELOCITY_ITERATIONS,BOX_POSITION_ITERATIONS);
      accumulator-=BOX_STEP;
   }

}

;

public by leonardo  2124  3  6  0

GUIDE - Javascript

------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------
References:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript

1. Objects
----------

	1.1 Core Objects
	----------------
	https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects

	Math, Object, Array, and String

	1.2 Custom Objects
	------------------

		1.2.1 Creating Custom Objects
		-----------------------------

			1.2.1.1 Creating objects using new Object() [not flexible]
			----------------------------------------------------------

			person = new Object()
			person.name = "Tim Scarfe"
			person.height = "6Ft"

			person.run = function() {
				this.state = "running"
				this.speed = "4ms^-1"
			}

			1.2.1.2 Creating objects using Literal Notation [not flexible]
			--------------------------------------------------------------

			timObject = {
				property1 : "Hello",
				property2 : "MmmMMm",
				property3 : ["mmm", 2, 3, 6, "kkk"],
				method1 : function(){alert("Method had been called" + this.property1)}
			};

			timObject.method1();
			alert(timObject.property3[2]) // will yield 3

			var circle = { x : 0, y : 0, radius: 2 } // another example

			// nesting is no problem.
			var rectangle = { 
				upperLeft : { x : 2, y : 2 },
				lowerRight : { x : 4, y : 4}
			}

			alert(rectangle.upperLeft.x) // will yield 2

			1.2.1.3 Object Constructor Function
			-----------------------------------

			An object constructor is merely a regular JavaScript function, so it's just as robust (ie: define parameters, call other functions etc). The difference between the two is that a constructor function is called via the new operator.

			function cat(name) {
				this.name = name;
				this.talk = function() {
					alert( this.name + " say meeow!" )
				}
			} 

			cat1 = new cat("felix")
			cat1.talk() //alerts "felix says meeow!"

			cat2 = new cat("ginger")
			cat2.talk() //alerts "ginger says meeow!"

			A questo oggetto possiamo aggiungere metodi tramite il prototype

			cat.prototype.changeName = function(name) {
				this.name = name;
			}

			firstCat = new cat("pursur")
			firstCat.changeName("Bill")
			firstCat.talk() //alerts "Bill says meeow!"

		1.2.2 Subclasses and Superclasses
		---------------------------------
		...

		1.2.3 Objects as Associative Arrays
		-----------------------------------

		// These are the same
		  object.property
		  object["property"]

		NOTA: come in LUA

		1.2.4 Calling Methods
		---------------------

		We can set this explicitly using Function#call (or Function#apply)
		Rif: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/call
		Rif: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/apply

		function Person(firstName) {
		  this.firstName = firstName;
		}

		Person.prototype.sayHello = function() {
		  alert("Hello, I'm " + this.firstName);
		};

		var person1 = new Person("Alice");
		var helloFunction = person1.sayHello;

		helloFunction.call(person1);                        // alerts "Hello, I'm Alice"




2. Namespaces in Javascript
---------------------------

Let's create a global object called MYAPP:

// global namespace
var MYAPP = MYAPP || {};

;