Java Code Examples for processing.core.PGraphics#rotateZ()

The following examples show how to use processing.core.PGraphics#rotateZ() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShaderSSAO.java    From haxademic with MIT License 6 votes vote down vote up
protected void drawCubesInCircle(PGraphics pg) {
	// spin it
	pg.rotateZ(progressRads);

	// draw plane
	pg.fill(100);
	pg.rect(0, 0, p.width * 3, p.height * 3);

	float radius = pg.width * 0.2f;
	for (int i = 0; i < 14; i++) {
		pg.fill(200f + 55f * P.sin(i), 200f + 55f * P.cos(i * 2f), 200f + 55f * P.sin(i));
		pg.pushMatrix();
		pg.translate(radius * P.sin(i + progressRads), radius * P.cos(i + progressRads), 0);
		pg.rotateX(progressRads + i);
		pg.rotateY(progressRads + i);
		pg.box(pg.height * 0.2f);
		pg.popMatrix();
	}
}
 
Example 2
Source File: ShaderSSAO.java    From haxademic with MIT License 6 votes vote down vote up
protected void drawFewCubes(PGraphics pg) {
		// spin it
		pg.rotateX(P.PI/3 + P.sin(progressRads) * 0.1f);

		// draw plane
		pg.fill(255);
		pg.rect(0, 0, p.width * 3, p.height * 3);

		float radius = pg.width * 0.2f;
		for (int i = 0; i < 24; i++) {
			pg.fill(60f + 55f * P.sin(i), 170f + 35f * P.cos(i * 2f), 150f + 75f * P.sin(i));
			pg.pushMatrix();
//			pg.translate(radius * P.sin(i/3f + progressRads), radius * P.cos(i/3f + progressRads), 0);
			pg.rotateX(P.TWO_PI * p.noise(i + 0.1f * P.cos(progressRads + i)));
			pg.rotateY(P.TWO_PI * p.noise(i + 0.1f * P.sin(progressRads + i)));
			pg.rotateZ(P.TWO_PI * p.noise(i + 0.1f * P.sin(progressRads + i * 20f)));
			pg.box(
					pg.height * P.sin(i + progressRads),
					pg.height * P.sin(i + progressRads) * 0.1f,
					pg.height * P.sin(i + progressRads) * 0.1f
					);
			pg.popMatrix();
		}
	}
 
Example 3
Source File: Particle3d.java    From haxademic with MIT License 5 votes vote down vote up
public void update(PGraphics pg) {
	if(available()) return;
	
	// update position
	if(gravity.mag() > 0) speed.add(gravity);
	if(acceleration != 1) speed.mult(acceleration);
	pos.add(speed);
	rotation.add(rotationSpeed);
	
	// update size
	sizeProgress.update();
	float curSize = size * Penner.easeOutSine(sizeProgress.value());
	if(sizeProgress.value() == 1) sizeProgress.setTarget(0);
	
	// draw image
	pg.pushMatrix();
	pg.translate(pos.x, pos.y, pos.z);
	pg.rotateX(rotation.x);
	pg.rotateY(rotation.y);
	pg.rotateZ(rotation.z);
	pg.fill(color);
	if(customShape != null) {
		pg.pushMatrix();
		pg.scale(Penner.easeOutExpo(sizeProgress.value()) * curSize / customShape.getHeight());
		pg.shape(customShape);
		pg.popMatrix();
	} else {
		if(isSphere) {
			pg.sphere(curSize/2f);
		} else {
			pg.box(curSize, curSize, curSize);
		}
	}
	pg.fill(255);
	pg.popMatrix();
}
 
Example 4
Source File: Shapes.java    From haxademic with MIT License 5 votes vote down vote up
public static void drawPyramid( PGraphics p, float shapeHeight, float baseWidth, boolean drawBase ){
	baseWidth *= P.HALF_PI;
	
	p.pushMatrix();
	p.rotateZ(P.radians(-45.0f));
	p.beginShape(P.TRIANGLES);
	
	int numSides = 4;
	float segmentCircumference = (2f*P.PI) / numSides;
	float halfBaseW = baseWidth / 2f;

	for( int i = 0; i < numSides; i++ )
	{
		p.vertex( 0, 0, shapeHeight );
		p.vertex( P.sin( i * segmentCircumference ) * halfBaseW, P.cos( i * segmentCircumference ) * halfBaseW, 0 );
		p.vertex( P.sin( (i + 1) * segmentCircumference ) * halfBaseW, P.cos( (i + 1) * segmentCircumference ) * halfBaseW, 0 );
	}
	
	if( drawBase ) {
		// base
		p.vertex( P.sin( 0 * segmentCircumference ) * halfBaseW, P.cos( 0 * segmentCircumference ) * halfBaseW, 0 );
		p.vertex( P.sin( 1 * segmentCircumference ) * halfBaseW, P.cos( 1 * segmentCircumference ) * halfBaseW, 0 );
		p.vertex( P.sin( 2 * segmentCircumference ) * halfBaseW, P.cos( 2 * segmentCircumference ) * halfBaseW, 0 );

		p.vertex( P.sin( 2 * segmentCircumference ) * halfBaseW, P.cos( 2 * segmentCircumference ) * halfBaseW, 0 );
		p.vertex( P.sin( 3 * segmentCircumference ) * halfBaseW, P.cos( 3 * segmentCircumference ) * halfBaseW, 0 );
		p.vertex( P.sin( 0 * segmentCircumference ) * halfBaseW, P.cos( 0 * segmentCircumference ) * halfBaseW, 0 );
	}
	
	p.endShape();
	p.popMatrix();
}
 
Example 5
Source File: OrientationUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static void setRotationTowards( PGraphics pg, PVector point1, PVector point2 ) {
	lookAt.set(point1);
	lookAt.sub(point2);
	float r = P.sqrt(lookAt.x * lookAt.x + lookAt.y * lookAt.y + lookAt.z * lookAt.z);
	float theta = P.atan2(lookAt.y, lookAt.x);
	float phi = P.acos(lookAt.z / r);
	pg.rotateZ(theta);
	pg.rotateY(phi);
	pg.rotateX(P.HALF_PI);
}
 
Example 6
Source File: OrientationUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static void setRotationTowards2(PGraphics pg, PVector point1, PVector point2) {
	// spin on y axis
	float yRads = MathUtil.getRadiansToTarget(point1.x, point1.z, point2.x, point2.z);
	// calculate z-tilt
	float c = point1.dist(point2);	 			// we have the diagonal distance
	float b = point1.y - point2.y;	 			// and y-difference
	float a = P.sqrt(P.sq(c) - P.sq(b));		// so we solve for a (c^2 - b^2 = a^2)
	float zRads = MathUtil.getRadiansToTarget(0, 0, a, b);	// get radians based on a/b (x/y) offset
	pg.rotateY(-yRads);
	pg.rotateZ(-zRads);
	pg.rotateZ(P.HALF_PI);
}