当前位置: 首页>>代码示例>>Java>>正文


Java FastTrig类代码示例

本文整理汇总了Java中org.newdawn.slick.util.FastTrig的典型用法代码示例。如果您正苦于以下问题:Java FastTrig类的具体用法?Java FastTrig怎么用?Java FastTrig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FastTrig类属于org.newdawn.slick.util包,在下文中一共展示了FastTrig类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import org.newdawn.slick.util.FastTrig; //导入依赖的package包/类
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	this.container = container;
	
	image = new Image("testdata/logo.tga", true);
	
	Image temp = new Image("testdata/palette_tool.png");
	container.setMouseCursor(temp, 0, 0);
	
	container.setIcons(new String[] {"testdata/icon.tga"});
	container.setTargetFrameRate(100);
	
	poly = new Polygon();
	float len = 100;
	
	for (int x=0;x<360;x+=30) {
		if (len == 100) {
			len = 50; 
		} else {
			len = 100;
		}
		poly.addPoint((float) FastTrig.cos(Math.toRadians(x)) * len, 
					  (float) FastTrig.sin(Math.toRadians(x)) * len);
	}
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:28,代码来源:GraphicsTest.java

示例2: createPoints

import org.newdawn.slick.util.FastTrig; //导入依赖的package包/类
/**
 * Generate the points to fill a corner arc.
 *
 * @param numberOfSegments How fine to make the ellipse.
 * @param radius The radius of the arc.
 * @param cx The x center of the arc.
 * @param cy The y center of the arc.
 * @param start The start angle of the arc.
 * @param end The end angle of the arc.
 * @return The points created.
 */
private List createPoints(int numberOfSegments, float radius, float cx, float cy, float start, float end) {
    ArrayList tempPoints = new ArrayList();

    int step = 360 / numberOfSegments;
    
    for (float a=start;a<=end+step;a+=step) {
        float ang = a;
        if (ang > end) {
            ang = end;
        }
        float x = (float) (cx + (FastTrig.cos(Math.toRadians(ang)) * radius));
        float y = (float) (cy + (FastTrig.sin(Math.toRadians(ang)) * radius));
        
        tempPoints.add(new Float(x));
        tempPoints.add(new Float(y));
    }
    
    return tempPoints;
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:31,代码来源:RoundedRectangle.java

示例3: setTheta

import org.newdawn.slick.util.FastTrig; //导入依赖的package包/类
/**
	 * Calculate the components of the vectors based on a angle
	 * 
	 * @param theta The angle to calculate the components from (in degrees)
	 */
	public void setTheta(double theta) {
		// Next lines are to prevent numbers like -1.8369701E-16
		// when working with negative numbers
		if ((theta < -360) || (theta > 360)) {
			theta = theta % 360;
		}
		if (theta < 0) {
			theta = 360 + theta;
		}
		double oldTheta = getTheta();
		if ((theta < -360) || (theta > 360)) {
			oldTheta = oldTheta % 360;
		}
		if (theta < 0) {
			oldTheta = 360 + oldTheta;
		}

		float len = length();
		x = len * (float) FastTrig.cos(StrictMath.toRadians(theta));
		y = len * (float) FastTrig.sin(StrictMath.toRadians(theta));
		
//		x = x / (float) FastTrig.cos(StrictMath.toRadians(oldTheta))
//				* (float) FastTrig.cos(StrictMath.toRadians(theta));
//		y = x / (float) FastTrig.sin(StrictMath.toRadians(oldTheta))
//				* (float) FastTrig.sin(StrictMath.toRadians(theta));
	}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:32,代码来源:Vector2f.java

示例4: drawArc

import org.newdawn.slick.util.FastTrig; //导入依赖的package包/类
/**
 * Draw an oval to the canvas
 * 
 * @param x1
 *            The x coordinate of the top left corner of a box containing
 *            the arc
 * @param y1
 *            The y coordinate of the top left corner of a box containing
 *            the arc
 * @param width
 *            The width of the arc
 * @param height
 *            The height of the arc
 * @param segments
 *            The number of line segments to use when drawing the arc
 * @param start
 *            The angle the arc starts at
 * @param end
 *            The angle the arc ends at
 */
public void drawArc(float x1, float y1, float width, float height,
		int segments, float start, float end) {
	predraw();
	TextureImpl.bindNone();
	currentColor.bind();

	while (end < start) {
		end += 360;
	}

	float cx = x1 + (width / 2.0f);
	float cy = y1 + (height / 2.0f);

	LSR.start();
	int step = 360 / segments;

	for (int a = (int) start; a < (int) (end + step); a += step) {
		float ang = a;
		if (ang > end) {
			ang = end;
		}
		float x = (float) (cx + (FastTrig.cos(Math.toRadians(ang)) * width / 2.0f));
		float y = (float) (cy + (FastTrig.sin(Math.toRadians(ang)) * height / 2.0f));

		LSR.vertex(x,y);
	}
	LSR.end();
	postdraw();
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:50,代码来源:Graphics.java

示例5: setTheta

import org.newdawn.slick.util.FastTrig; //导入依赖的package包/类
/**
     * Calculate the components of the vectors based on a angle
     *
     * @param theta The angle to calculate the components from (in degrees)
     */
    void setTheta(double theta) {
        // Next lines are to prevent numbers like -1.8369701E-16
        // when working with negative numbers
        if ((theta < -360) || (theta > 360)) {
            theta = theta % 360;
        }
        if (theta < 0) {
            theta = 360 + theta;
        }
        double oldTheta = getTheta();
        if ((theta < -360) || (theta > 360)) {
            oldTheta = oldTheta % 360;
        }
        if (theta < 0) {
            oldTheta = 360 + oldTheta;
        }

        float len = length();
        x = len * (float) FastTrig.cos(StrictMath.toRadians(theta));
        y = len * (float) FastTrig.sin(StrictMath.toRadians(theta));

//        x = x / (float) FastTrig.cos(StrictMath.toRadians(oldTheta))
//                * (float) FastTrig.cos(StrictMath.toRadians(theta));
//        y = x / (float) FastTrig.sin(StrictMath.toRadians(oldTheta))
//                * (float) FastTrig.sin(StrictMath.toRadians(theta));
    }
 
开发者ID:FOShameDotOrg,项目名称:fuzzy-octo-shame,代码行数:32,代码来源:Vector2f.java

示例6: drawArc

import org.newdawn.slick.util.FastTrig; //导入依赖的package包/类
/**
 * Draw an oval to the canvas
 *
 * @param x1
 *            The x coordinate of the top left corner of a box containing the arc
 * @param y1
 *            The y coordinate of the top left corner of a box containing the arc
 * @param width
 *            The width of the arc
 * @param height
 *            The height of the arc
 * @param segments
 *            The number of line segments to use when drawing the arc
 * @param start
 *            The angle the arc starts at
 * @param end
 *            The angle the arc ends at
 */
void drawArc(float x1, float y1, float width, float height, int segments, float start, float end) {
    predraw();
    TextureImpl.bindNone();
    currentColor.bind();

    while (end < start) {
        end += 360;
    }

    float cx = x1 + (width / 2.0f);
    float cy = y1 + (height / 2.0f);

    LSR.start();
    int step = 360 / segments;

    for (int a = (int) start; a < (int) (end + step); a += step) {
        float ang = a;
        if (ang > end) {
            ang = end;
        }
        float x = (float) (cx + (FastTrig.cos(Math.toRadians(ang)) * width / 2.0f));
        float y = (float) (cy + (FastTrig.sin(Math.toRadians(ang)) * height / 2.0f));

        LSR.vertex(x, y);
    }
    LSR.end();
    postdraw();
}
 
开发者ID:FOShameDotOrg,项目名称:fuzzy-octo-shame,代码行数:47,代码来源:Graphics.java

示例7: createPoints

import org.newdawn.slick.util.FastTrig; //导入依赖的package包/类
/**
 * Generate the points to outline this ellipse.
 *
 */
protected void createPoints() {
    ArrayList tempPoints = new ArrayList();

    maxX = -Float.MIN_VALUE;
    maxY = -Float.MIN_VALUE;
    minX = Float.MAX_VALUE;
    minY = Float.MAX_VALUE;

    float start = 0;
    float end = 359;
    
    float cx = x + radius1;
    float cy = y + radius2;
    
    int step = 360 / segmentCount;
    
    for (float a=start;a<=end+step;a+=step) {
        float ang = a;
        if (ang > end) {
            ang = end;
        }
        float newX = (float) (cx + (FastTrig.cos(Math.toRadians(ang)) * radius1));
        float newY = (float) (cy + (FastTrig.sin(Math.toRadians(ang)) * radius2));

        if(newX > maxX) {
            maxX = newX;
        }
        if(newY > maxY) {
            maxY = newY;
        }
        if(newX < minX) {
        	minX = newX;
        }
        if(newY < minY) {
        	minY = newY;
        }
        
        tempPoints.add(new Float(newX));
        tempPoints.add(new Float(newY));
    }
    points = new float[tempPoints.size()];
    for(int i=0;i<points.length;i++) {
        points[i] = ((Float)tempPoints.get(i)).floatValue();
    }
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:50,代码来源:Ellipse.java

示例8: drawEmbedded

import org.newdawn.slick.util.FastTrig; //导入依赖的package包/类
/**
 * Unlike the other drawEmbedded methods, this allows for the embedded image
 * to be rotated. This is done by applying a rotation transform to each 
 * vertex of the image. This ignores getRotation but depends on the 
 * center x/y (scaled accordingly to the new width/height).
 * 
 * @param x the x to render the image at
 * @param y the y to render the image at
 * @param width the new width to render the image
 * @param height the new height to render the image
 * @param rotation the rotation to render the image, using getCenterOfRotationX/Y
 *
 * @author davedes
 */
public void drawEmbedded(float x, float y, float width, float height, float rotation) {
	if (rotation==0) {
		drawEmbedded(x, y, width, height);
		return;
	}
	init();
	float scaleX = width/this.width;
	float scaleY = height/this.height;

	float cx = getCenterOfRotationX()*scaleX;
	float cy = getCenterOfRotationY()*scaleY;

	float p1x = -cx;
	float p1y = -cy;
	float p2x = width - cx;
	float p2y = -cy;
	float p3x = width - cx;
	float p3y = height - cy;
	float p4x = -cx;
	float p4y = height - cy;

	double rad = Math.toRadians(rotation);
	final float cos = (float) FastTrig.cos(rad);
	final float sin = (float) FastTrig.sin(rad);

	float tx = getTextureOffsetX();
	float ty = getTextureOffsetY();
	float tw = getTextureWidth();
	float th = getTextureHeight();

	float x1 = (cos * p1x - sin * p1y) + cx; // TOP LEFT
	float y1 = (sin * p1x + cos * p1y) + cy;
	float x2 = (cos * p4x - sin * p4y) + cx; // BOTTOM LEFT
	float y2 = (sin * p4x + cos * p4y) + cy;
	float x3 = (cos * p3x - sin * p3y) + cx; // BOTTOM RIGHT
	float y3 = (sin * p3x + cos * p3y) + cy;
	float x4 = (cos * p2x - sin * p2y) + cx; // TOP RIGHT
	float y4 = (sin * p2x + cos * p2y) + cy;
	if (corners == null) {
		GL.glTexCoord2f(tx, ty);
		GL.glVertex3f(x+x1, y+y1, 0);
		GL.glTexCoord2f(tx, ty + th);
		GL.glVertex3f(x+x2, y+y2, 0);
		GL.glTexCoord2f(tx + tw, ty + th);
		GL.glVertex3f(x+x3, y+y3, 0);
		GL.glTexCoord2f(tx + tw, ty);
		GL.glVertex3f(x+x4, y+y4, 0);
	} else {
		corners[TOP_LEFT].bind();
		GL.glTexCoord2f(tx, ty);
		GL.glVertex3f(x+x1, y+y1, 0);
		corners[BOTTOM_LEFT].bind();
		GL.glTexCoord2f(tx, ty + th);
		GL.glVertex3f(x+x2, y+y2, 0);
		corners[BOTTOM_RIGHT].bind();
		GL.glTexCoord2f(tx + tw, ty + th);
		GL.glVertex3f(x+x3, y+y3, 0);
		corners[TOP_RIGHT].bind();
		GL.glTexCoord2f(tx + tw, ty);
		GL.glVertex3f(x+x4, y+y4, 0);
	}
}
 
开发者ID:yugecin,项目名称:opsu-dance,代码行数:77,代码来源:Image.java


注:本文中的org.newdawn.slick.util.FastTrig类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。