Search Results

Search found 2826 results on 114 pages for 'michael dy'.

Page 4/114 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • LibGDX onTouch() method Array and flip method

    - by johnny-b
    How can I add this on my application. i want to use the onTouch() method from the implementation of the InputProcessor to kill the enemies on screen. how do i do that? do i have to do anything to the enemy class? also i am trying to add a Array of enemies and it keeps throwing exceptions or the bullet now is facing LEFT <--- again after I used the flip method in the bullet class. All the code is below so please anyone feel free to have a look thanks. please help Thank you M // This is the bullet class. public class Bullet extends Sprite { public static final float BULLET_HOMING = 6000; public static final float BULLET_SPEED = 300; private Vector2 velocity; private float lifetime; private Rectangle bul; public Bullet(float x, float y) { velocity = new Vector2(0, 0); setPosition(x, y); AssetLoader.bullet1.flip(true, false); AssetLoader.bullet2.flip(true, false); setSize(AssetLoader.bullet1.getWidth(), AssetLoader.bullet1.getHeight()); bul = new Rectangle(); } public void update(float delta) { float targetX = GameWorld.getBall().getX(); float targetY = GameWorld.getBall().getY(); float dx = targetX - getX(); float dy = targetY - getY(); float distToTarget = (float) Math.sqrt(dx * dx + dy * dy); dx /= distToTarget; dy /= distToTarget; dx *= BULLET_HOMING; dy *= BULLET_HOMING; velocity.x += dx * delta; velocity.y += dy * delta; float vMag = (float) Math.sqrt(velocity.x * velocity.x + velocity.y * velocity.y); velocity.x /= vMag; velocity.y /= vMag; velocity.x *= BULLET_SPEED; velocity.y *= BULLET_SPEED; bul.set(getX(), getY(), getOriginX(), getOriginY()); Vector2 v = velocity.cpy().scl(delta); setPosition(getX() + v.x, getY() + v.y); setOriginCenter(); setRotation(velocity.angle()); } public Rectangle getBounds() { return bul; } public Rectangle getBounds1() { return this.getBoundingRectangle(); } } // This is the class where i load all the images from public class AssetLoader { public static Texture texture; public static TextureRegion bg, ball1, ball2; public static Animation bulletAnimation, ballAnimation; public static Sprite bullet1, bullet2; public static void load() { texture = new Texture(Gdx.files.internal("SpriteN1.png")); texture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest); bg = new TextureRegion(texture, 80, 421, 395, 30); bg.flip(false, true); ball1 = new TextureRegion(texture, 0, 321, 32, 32); ball1.flip(false, true); ball2 = new TextureRegion(texture, 32, 321, 32, 32); ball2.flip(false, true); bullet1 = new Sprite(texture, 380, 350, 45, 20); bullet1.flip(false, true); bullet2 = new Sprite(texture, 425, 350, 45, 20); bullet2.flip(false, true); TextureRegion[] balls = { ball1, ball2 }; ballAnimation = new Animation(0.16f, balls); ballAnimation.setPlayMode(Animation.PlayMode.LOOP); } Sprite[] bullets = { bullet1, bullet2 }; bulletAnimation = new Animation(0.06f, aims); bulletAnimation.setPlayMode(Animation.PlayMode.LOOP); } public static void dispose() { texture.dispose(); } // This is for the rendering or drawing onto the screen/canvas. public class GameRenderer { private Bullet bullet; private Ball ball; public GameRenderer(GameWorld world) { myWorld = world; cam = new OrthographicCamera(); cam.setToOrtho(true, 480, 320); batcher = new SpriteBatch(); // Attach batcher to camera batcher.setProjectionMatrix(cam.combined); shapeRenderer = new ShapeRenderer(); shapeRenderer.setProjectionMatrix(cam.combined); // Call helper methods to initialize instance variables initGameObjects(); initAssets(); } private void initGameObjects() { ball = GameWorld.getBall(); bullet = myWorld.getBullet(); scroller = myWorld.getScroller(); } private void initAssets() { ballAnimation = AssetLoader.ballAnimation; bulletAnimation = AssetLoader.bulletAnimation; } public void render(float runTime) { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT); batcher.begin(); batcher.disableBlending(); batcher.enableBlending(); batcher.draw(AssetLoader.ballAnimation.getKeyFrame(runTime), ball.getX(), ball.getY(), ball.getWidth(), ball.getHeight()); batcher.draw(AssetLoader.bulletAnimation.getKeyFrame(runTime), bullet.getX(), bullet.getY(), bullet.getOriginX(), bullet.getOriginY(), bullet.getWidth(), bullet.getHeight(), 1.0f, 1.0f, bullet.getRotation()); // End SpriteBatch batcher.end(); } } // this is to load the image etc on the screen i guess public class GameWorld { public static Ball ball; private Bullet bullet; private ScrollHandler scroller; public GameWorld() { ball = new Ball(480, 273, 32, 32); bullet = new Bullet(10, 10); scroller = new ScrollHandler(0); } public void update(float delta) { ball.update(delta); bullet.update(delta); scroller.update(delta); } public static Ball getBall() { return ball; } public ScrollHandler getScroller() { return scroller; } public Bullet getBullet() { return bullet; } } //This is the input handler class public class InputHandler implements InputProcessor { private Ball myBall; private Bullet bullet; private GameRenderer aims; // Ask for a reference to the Soldier when InputHandler is created. public InputHandler(Ball ball) { myBall = ball; } @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { return false; } @Override public boolean keyDown(int keycode) { return false; } @Override public boolean keyUp(int keycode) { return false; } @Override public boolean keyTyped(char character) { return false; } @Override public boolean touchUp(int screenX, int screenY, int pointer, int button) { return false; } @Override public boolean touchDragged(int screenX, int screenY, int pointer) { return false; } @Override public boolean mouseMoved(int screenX, int screenY) { return false; } @Override public boolean scrolled(int amount) { return false; } } i am rendering all graphics in a GameRender class and a gameworld class if you need more info please let me know I am trying to make the array work but keep finding that when an array is initialized then the bullet fips back to the original and ends up being backwards???? and if I create an array I keep getting Exceptions throw??? Thank you for any help given.

    Read the article

  • Chinese footwear retailer Daphne on choosing Oracle Retail solutions

    - by user801960
    In January, leading Chinese footwear brand Daphne announced that they had chosen Oracle Retail as a solution provider for its expansion strategy. We were delighted to host Michael Hu, Chief Operations Officer of Daphne, at our exclusive Retail Exchange event in New York in January. We interviewed Michael about Daphne, Daphne's plans for the future and how Oracle's solutions will play a role in that future. The video is below. We are very grateful to Michael for taking the time to speak to us. To find out more about how Daphne is using Oracle, see the full press release HERE. To find out more about Oracle Retail solutions and how Oracle Retail can help your business, visit http://www.oracle.com/oms/retail/index.html

    Read the article

  • Determining the angle to fire a shot when target and shooter moves, and bullet moves with shooter velocity added in

    - by Azaral
    I saw this question: Predicting enemy position in order to have an object lead its target and followed the link in the answer to stack overflow. In the stack overflow page I used the 2nd answer, the one that is a large mathematical derivation. My situation is a little different though. My first question though is will the answer provided in the stack overflow page even work to begin with, assuming the original circumstances of moving target and stationary shooter. My situation is a little different than that situation. My target moves, the shooter moves, and the bullets from the shooter start off with the velocities in x and y added to the bullets' x and y velocities. If you are sliding to the right, the bullets will remain in front of you as you move so as long as your velocity remains constant. What I'm trying to do is to get the enemy to be able to determine where they need to shoot in order to hit the player. Unless the player and enemy is stationary, the velocity from the ship adding to the velocity of the bullets will cause a miss. I'd rather like to prevent that. I used the formula in the stack overflow answer and did what I thought were the appropriate adjustments. I've been banging at this for the last four hours and I just can't make it click. It is probably something really simple and boneheaded that I am missing (that seems to be a lot of my problems lately). Here is the solution presented from the stack overflow answer: It boils down to solving a quadratic equation of the form: a * sqr(x) + b * x + c == 0 Note that by sqr I mean square, as opposed to square root. Use the following values: a := sqr(target.velocityX) + sqr(target.velocityY) - sqr(projectile_speed) b := 2 * (target.velocityX * (target.startX - cannon.X) + target.velocityY * (target.startY - cannon.Y)) c := sqr(target.startX - cannon.X) + sqr(target.startY - cannon.Y) Now we can look at the discriminant to determine if we have a possible solution. disc := sqr(b) - 4 * a * c If the discriminant is less than 0, forget about hitting your target -- your projectile can never get there in time. Otherwise, look at two candidate solutions: t1 := (-b + sqrt(disc)) / (2 * a) t2 := (-b - sqrt(disc)) / (2 * a) Note that if disc == 0 then t1 and t2 are equal. If there are no other considerations such as intervening obstacles, simply choose the smaller positive value. (Negative t values would require firing backward in time to use!) Substitute the chosen t value back into the target's position equations to get the coordinates of the leading point you should be aiming at: aim.X := t * target.velocityX + target.startX aim.Y := t * target.velocityY + target.startY Here is my code, after being corrected by Sam Hocevar (thank you again for your help!). It still doesn't work. For some reason it never enters the section of code inside the if(disc = 0) (obviously because it is always less than zero but...). However, if I plug the numbers from my game log on the enemy and player positions and velocities it outputs a valid firing solution. I have looked at the code side by side a couple of times now and I can't find any differences. There has got to be something simple I'm missing here. If someone else could look at this code and determine what is going on here I'd appreciate it. I know it's not going through that section because if it were, shouldShoot would become true and the enemy would be blasting away at the player. This section calls the function in question, CalculateShootHeading() if(shouldMove) { UseEngines(); } x += xVelocity; y += yVelocity; CalculateShootHeading(); if(shouldShoot) { ShootWeapons(); } UpdateWeapons(); This is CalculateShootHeading(). This is inside the enemy class so x and y are the enemy's x and y and the same with velocity. One output from my game log gives Player X = 2108, Player Y = -180.956, Player X velocity = 10.9949, Player Y Velocity = -6.26017, Enemy X = 1988.31, Enemy Y = -339.051, Enemy X velocity = 1.81666, Enemy Y velocity = -9.67762, 0 enemy projectiles. The output from the console tester is Bullet position = 2210.49, -239.313 and Player Position = 2210.49, -239.313. This doesn't make any sense. The only thing that could be different is the code or the input into my function in the game and I've checked that and I don't think that it is wrong as it's updated before this and never changed. float const bulletSpeed = 30.f; float const dx = playerX - x; float const dy = playerY - y; float const vx = playerXVelocity - xVelocity; float const vy = playerYVelocity - yVelocity; float const a = vx * vx + vy * vy - bulletSpeed * bulletSpeed; float const b = 2.f * (vx * dx + vy * dy); float const c = dx * dx + dy * dy; float const disc = b * b - 4.f * a * c; shouldShoot = false; if (disc >= 0.f) { float t0 = (-b - std::sqrt(disc)) / (2.f * a); float t1 = (-b + std::sqrt(disc)) / (2.f * a); if (t0 < 0.f || (t1 < t0 && t1 >= 0.f)) { t0 = t1; } if (t0 >= 0.f) { float shootx = vx + dx / t0; float shooty = vy + dy / t0; heading = std::atan2(shooty, shootx) * RAD2DEGREE; } shouldShoot = true; }

    Read the article

  • lwjgl isKeyDown canceling out other keys

    - by AKrush95
    While trying to create a simple game where a square is manipulated via the keyboard keys, I have come across a small, rather irritating problem. I would like it to work so that when the opposite directional key is pressed, the character will stop; the character may move the other two directions while stopped in this situation. This works perfectly with LEFT and RIGHT held down; the player may move UP or DOWN. If UP and DOWN are held down, however, the player will not move, nor will Java recognize that the LEFT or RIGHT keys were pressed. import java.util.ArrayList; import java.util.Random; import org.lwjgl.*; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.*; import static org.lwjgl.opengl.GL11.*; public class Main { private Man p; private ArrayList<Integer> keysDown, keysUp; public Main() { try { Display.setDisplayMode(new DisplayMode(640, 480)); Display.setTitle("LWJGLHelloWorld"); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); } p = new Man(0, 0); keysDown = new ArrayList<>(); keysUp = new ArrayList<>(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, 640, 480, 0, 1, -1); glMatrixMode(GL_MODELVIEW); while (!Display.isCloseRequested()) { glClear(GL_COLOR_BUFFER_BIT); checkKeys(); p.draw(); Display.update(); Display.sync(60); } Display.destroy(); } public void checkKeys() { ArrayList<Integer> keys = new ArrayList<>(); keys.add(Keyboard.KEY_A); keys.add(Keyboard.KEY_D); keys.add(Keyboard.KEY_W); keys.add(Keyboard.KEY_S); for (int key : keys) { if (Keyboard.isKeyDown(key)) keysDown.add(key); else keysUp.add(key); } keysDown.removeAll(keysUp); keysUp = new ArrayList<>(); int speed = 4; int dx = 0; int dy = 0; if (keysDown.contains(keys.get(2))) { System.out.println("keyUP"); dy -= speed; } if (keysDown.contains(keys.get(3))) { System.out.println("keyDOWN"); dy += speed; } if (keysDown.contains(keys.get(0))) { System.out.println("keyLEFT"); dx -= speed; } if (keysDown.contains(keys.get(1))) { System.out.println("keyRIGHT"); dx += speed; } //if (keysDown.contains(keys.get(0)) && keysDown.contains(keys.get(1))) dx = 0; //if (keysDown.contains(keys.get(2)) && keysDown.contains(keys.get(3))) dy = 0; p.update(dx, dy); } public static void main(String[] args) { new Main(); } class Man { public int x, y, w, h; public float cR, cG, cB; public Man(int x, int y) { this.x = x; this.y = y; w = 50; h = 50; Random rand = new Random(); cR = rand.nextFloat(); cG = rand.nextFloat(); cB = rand.nextFloat(); } public void draw() { glColor3f(cR, cG, cB); glRecti(x, y, x+w, y+h); } public void update(int dx, int dy) { x += dx; y += dy; } } } That is the code that I am working with. In addition, I am unsure how to compile an executable jar that is using the lwjgl library in addition to slick-util.

    Read the article

  • Can't add any PPA's after reinstalling Ubuntu 13.10

    - by Michael Clare
    I can't add any PPA's at all after reinstalling Ubuntu 13.10. Here is what it says: michael@MikesKomputer:~$ sudo add-apt-repository ppa:atareao/atareao Cannot add PPA: 'ppa:atareao/atareao'. Please check that the PPA name or format is correct. This repository is working as far as I know. The problem is that I can't add any new repositories. Even if I can use the Software Center, I can't have my system with the add-apt-repository command broken.

    Read the article

  • Virtualization of the human race interactivity and beyond. [on hold]

    - by J Michael Caldwell
    We are in the processes of attempting this lofty goal. It requires multidiscipline advancements over long periods of time. Achieving this requires a great deal of science advancement including major programming and algorithm developments. These requirements are going to be ongoing and will be required well into the next century. Does anyone know of individuals or feel themselves that they might be knowledgable or interested in this endeavor? Details upon request. Thanks Michael

    Read the article

  • Delayed startup of network icon (wi-fi)

    - by Michael Dy
    When my Windows 7 Starter netbook boots up and after everything is loaded, it takes about five minutes before the network icon near the clock becomes functional. When there's an available wi-fi signal (which automatically connects to my netbook as preconfigured) after the boot, my netbook seamlessly connects to it even if the network icon cannot be clicked or accessed. (The icon is shown to be loading for about five minutes.) During this time, when I go to Network and Sharing Center, it takes the same time to load. So even while the icon and the Center cannot be accessed, I can surf the Internet. When my netbook was still new, it didn't have this issue. How do I fix this?

    Read the article

  • Wi-Fi connected but can't go to any site

    - by Michael Dy
    My Windows 7 laptop can connect to our Wi-Fi signal, I can sign in on Yahoo! Messenger, but I can't go to any site. I can access the Net on other devices. The issue started a few weeks ago, so I've been troubleshooting since then in vain. There's no virus, and I already used System Restore. In Wireless Network Connection Status, the received activity is greater than the sent activity. I turned off Windows Firewall and still no Net access. My ping tests: How do I fix this?

    Read the article

  • How to make a character jump, both on objects and just normal jump.

    - by haxerflaxer
    Hi, I'm kind of a beginner when it comes to java programming, and I have a project in school where I'm going to create a game much like Icy Tower. And my question is, how am I going to write to make the character stand on the ground and be able to jump up on objects? Here's my code so far: Part one package Sprites; import java.awt.Image; import java.awt.event.KeyEvent; import javax.swing.ImageIcon; public class jumper { private String jump = "oka.png"; private int dx; private int dy; private int x; private int y; private Image image; public jumper() { ImageIcon ii = new ImageIcon(this.getClass().getResource(jump)); image = ii.getImage(); x = 50; y = 100; } public void move() { x += dx; y += dy; } public int getX() { return x; } public int getY() { return y; } public Image getImage() { return image; } public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_LEFT) { dx = -5; ImageIcon ii = new ImageIcon(this.getClass().getResource("oki.png")); image = ii.getImage(); } if (key == KeyEvent.VK_RIGHT){ dx = 5; ImageIcon ii = new ImageIcon(this.getClass().getResource("oka.png")); image = ii.getImage(); } if (key == KeyEvent.VK_SPACE) { dy = -5; } if (key == KeyEvent.VK_DOWN) { dy = 5; } } public void keyReleased(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_LEFT) { dx = 0; } if (key == KeyEvent.VK_RIGHT){ dx = 0; } if (key == KeyEvent.VK_SPACE) { dy = 0; } if (key == KeyEvent.VK_DOWN) { dy = 0; } } } Part two package Sprites; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import javax.swing.JPanel; import javax.swing.Timer; public class board extends JPanel implements ActionListener { private Timer klocka; private jumper jumper; public board() { addKeyListener(new TAdapter()); setFocusable(true); setBackground(Color.WHITE); setDoubleBuffered(true); jumper = new jumper(); klocka = new Timer(5, this); klocka.start(); } public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D)g; g2d.drawImage(jumper.getImage(), jumper.getX(), jumper.getY(), this); Toolkit.getDefaultToolkit().sync(); g.dispose(); } public void actionPerformed(ActionEvent e) { jumper.move(); repaint(); } private class TAdapter extends KeyAdapter { public void keyReleased(KeyEvent e) { jumper.keyReleased(e); } public void keyPressed(KeyEvent e) { jumper.keyPressed(e); } } } Part three package Sprites; import javax.swing.JFrame; public class RType extends JFrame { public RType() { add(new board()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(800, 600); setLocationRelativeTo(null); setTitle("R - type"); setResizable(false); setVisible(true); } public static void main(String[] args) { new RType(); } } I really appreciate all the help I can get!

    Read the article

  • How do you make a character jump, both on objects and just normal jump?

    - by haxerflaxer
    Hi, I'm kind of a beginner when it comes to java programming, and I have a project in school where I'm going to create a game much like Icy Tower. And my question is, how am I going to write to make the character stand on the ground and be able to jump up on objects? Here's my code so far: Part one package Sprites; import java.awt.Image; import java.awt.event.KeyEvent; import javax.swing.ImageIcon; public class jumper { private String jump = "oka.png"; private int dx; private int dy; private int x; private int y; private Image image; public jumper() { ImageIcon ii = new ImageIcon(this.getClass().getResource(jump)); image = ii.getImage(); x = 50; y = 100; } public void move() { x += dx; y += dy; } public int getX() { return x; } public int getY() { return y; } public Image getImage() { return image; } public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_LEFT) { dx = -5; ImageIcon ii = new ImageIcon(this.getClass().getResource("oki.png")); image = ii.getImage(); } if (key == KeyEvent.VK_RIGHT){ dx = 5; ImageIcon ii = new ImageIcon(this.getClass().getResource("oka.png")); image = ii.getImage(); } if (key == KeyEvent.VK_SPACE) { dy = -5; } if (key == KeyEvent.VK_DOWN) { dy = 5; } } public void keyReleased(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_LEFT) { dx = 0; } if (key == KeyEvent.VK_RIGHT){ dx = 0; } if (key == KeyEvent.VK_SPACE) { dy = 0; } if (key == KeyEvent.VK_DOWN) { dy = 0; } } } Part two package Sprites; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import javax.swing.JPanel; import javax.swing.Timer; public class board extends JPanel implements ActionListener { private Timer klocka; private jumper jumper; public board() { addKeyListener(new TAdapter()); setFocusable(true); setBackground(Color.WHITE); setDoubleBuffered(true); jumper = new jumper(); klocka = new Timer(5, this); klocka.start(); } public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D)g; g2d.drawImage(jumper.getImage(), jumper.getX(), jumper.getY(), this); Toolkit.getDefaultToolkit().sync(); g.dispose(); } public void actionPerformed(ActionEvent e) { jumper.move(); repaint(); } private class TAdapter extends KeyAdapter { public void keyReleased(KeyEvent e) { jumper.keyReleased(e); } public void keyPressed(KeyEvent e) { jumper.keyPressed(e); } } } Part three package Sprites; import javax.swing.JFrame; public class RType extends JFrame { public RType() { add(new board()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(800, 600); setLocationRelativeTo(null); setTitle("R - type"); setResizable(false); setVisible(true); } public static void main(String[] args) { new RType(); } } I really appreciate all the help I can get!

    Read the article

  • In Clojure - How do I access keys in a vector of structs

    - by Nick
    I have the following vector of structs: (defstruct #^{:doc "Basic structure for book information."} book :title :authors :price) (def #^{:doc "The top ten Amazon best sellers on 16 Mar 2010."} best-sellers [(struct book "The Big Short" ["Michael Lewis"] 15.09) (struct book "The Help" ["Kathryn Stockett"] 9.50) (struct book "Change Your Prain, Change Your Body" ["Daniel G. Amen M.D."] 14.29) (struct book "Food Rules" ["Michael Pollan"] 5.00) (struct book "Courage and Consequence" ["Karl Rove"] 16.50) (struct book "A Patriot's History of the United States" ["Larry Schweikart","Michael Allen"] 12.00) (struct book "The 48 Laws of Power" ["Robert Greene"] 11.00) (struct book "The Five Thousand Year Leap" ["W. Cleon Skousen","James Michael Pratt","Carlos L Packard","Evan Frederickson"] 10.97) (struct book "Chelsea Chelsea Bang Bang" ["Chelsea Handler"] 14.03) (struct book "The Kind Diet" ["Alicia Silverstone","Neal D. Barnard M.D."] 16.00)]) I would like to sum the prices of all the books in the vector. What I have is the following: (defn get-price "Same as print-book but handling multiple authors on a single book" [ {:keys [title authors price]} ] price) Then I: (reduce + (map get-price best-sellers)) Is there a way of doing this without mapping the "get-price" function over the vector? Or is there an idiomatic way of approaching this problem?

    Read the article

  • 2D polygon triangulation

    - by logank9
    The code below is my attempt at triangulation. It outputs the wrong angles (it read a square's angles as 90, 90. 90, 176) and draws the wrong shapes. What am I doing wrong? //use earclipping to generate a list of triangles to draw std::vector<vec> calcTriDraw(std::vector<vec> poly) { std::vector<double> polyAngles; //get angles for(unsigned int i = 0;i < poly.size();i++) { int p1 = i - 1; int p2 = i; int p3 = i + 1; if(p3 > int(poly.size())) p3 -= poly.size(); if(p1 < 0) p1 += poly.size(); //get the angle from 3 points double dx, dy; dx = poly[p2].x - poly[p1].x; dy = poly[p2].y - poly[p1].y; double a = atan2(dy,dx); dx = poly[p3].x - poly[p2].x; dy = poly[p3].y - poly[p2].y; double b = atan2(dy,dx); polyAngles.push_back((a-b)*180/PI); } std::vector<vec> triList; for(unsigned int i = 0;i < poly.size() && poly.size() > 2;i++) { int p1 = i - 1; int p2 = i; int p3 = i + 1; if(p3 > int(poly.size())) p3 -= poly.size(); if(p1 < 0) p1 += poly.size(); if(polyAngles[p2] >= 180) { continue; } else { triList.push_back(poly[p1]); triList.push_back(poly[p2]); triList.push_back(poly[p3]); poly.erase(poly.begin()+p2); std::vector<vec> add = calcTriDraw(poly); triList.insert(triList.end(), add.begin(), add.end()); break; } } return triList; }

    Read the article

  • extjs how to make a nested child using xTemplate when we don't know how deep is it?

    - by Ebo the gordon
    first, sorry if my english bad,.... in my script, variable tplData below is dynamic,... (lets say it generates from database) so, every chid, can have another child. and so on,.... now, i'm stack how to iteration it,.. var tplData = [{ name : 'Naomi White' },{ name : 'Yoko Ono' },{ name : 'John Smith', child : [{ name:'Michael (John\'s son)', child: [{ name : 'Brad (Michael\'s son,John\'s grand son)' },{ name : 'Brid (Michael\'s son,John\'s grand son)', child: [{ name:'Buddy (Brid\'s son,Michael\'s grand son)' }] },{ name : 'Brud (Michael\'s son,John\'s grand son)' }] }] }]; var myTpl = new Ext.XTemplate( '<tpl for=".">', '<div style="background-color: {color}; margin: 10px;">', '<b> Name :</b> {name}<br />', // how to make this over and over every child (while it has ) '<tpl if="typeof child !=\'undefined\'">', '<b> Child : </b>', '<tpl for="child">', '{name} <br />', '</tpl>', '</tpl>', /////////////////////////////////////// '</div>', '</tpl>' ); myTpl.compile(); myTpl.overwrite(document.body, tplData);

    Read the article

  • how to avoid clutch billiard balls?

    - by Nait87
    I'm working on the simple behaviour of billiard balls in a collision with each other. All works normal, but there was a problem when facing a few easy balls is the effect of coupling balls and they're cool with each other. Tell me how to prevent this. bool MGBilliard::CollisingBall(CCPoint curr_point, CCPoint next_point) { float dx = next_point.x - (curr_point.x + dvdt.x); float dy = next_point.y - (curr_point.y - dvdt.y); float d = dx*dx+dy*dy; return d <= BALL_RADIUS * BALL_RADIUS; } double MGBilliard::angleCollisionBalls(Ball* current, Ball* next) { double na; double dx = fabs(next->location.x - current->location.x); double dy = fabs(next->location.y - current->location.y); na = atan(fabs(dy/dx)); if(atan(fabs(current->location.y/current->location.x)) < atan(fabs(next->location.y/next->location.x))) na = current->angle - na; else if(atan(fabs(current->location.y/current->location.x)) > atan(fabs(next->location.y/next->location.x))) na = current->angle + na; return na; } for(unsigned int i = 0;i<BALL_COUNT;++i) { if(vBalls[i]->speed > 0){ vBalls[i]->speed += vBalls[i]->acceleration; float dsdt = vBalls[i]->speed*dt; dvdt.x = dsdt*cos(vBalls[i]->angle); dvdt.y = dsdt*sin(vBalls[i]->angle); vBalls[i]->location.x += dvdt.x; vBalls[i]->location.y += dvdt.y; for(unsigned int j = 1; j < BALL_COUNT; ++j) { if(i == j) continue; if(CollisingBall(vBalls[i]->spriteBall->getPosition(),vBalls[j]->spriteBall->getPosition())) { vBalls[j]->speed = 600; double angle; angle = angleCollisionBalls(vBalls[i],vBalls[j]); vBalls[i]->angle = (float)-angle; vBalls[j]->angle = (float)angle; } } } }

    Read the article

  • How can I draw an arrow at the edge of the screen pointing to an object that is off screen?

    - by Adam Henderson
    I am wishing to do what is described in this topic: http://www.allegro.cc/forums/print-thread/283220 I have attempted a variety of the methods mentioned here. First I tried to use the method described by Carrus85: Just take the ratio of the two triangle hypontenuses (doesn't matter which triagle you use for the other, I suggest point 1 and point 2 as the distance you calculate). This will give you the aspect ratio percentage of the triangle in the corner from the larger triangle. Then you simply multiply deltax by that value to get the x-coordinate offset, and deltay by that value to get the y-coordinate offset. But I could not find a way to calculate how far the object is away from the edge of the screen. I then tried using ray casting (which I have never done before) suggested by 23yrold3yrold: Fire a ray from the center of the screen to the offscreen object. Calculate where on the rectangle the ray intersects. There's your coordinates. I first calculated the hypotenuse of the triangle formed by the difference in x and y positions of the two points. I used this to create a unit vector along that line. I looped through that vector until either the x coordinate or the y coordinate was off the screen. The two current x and y values then form the x and y of the arrow. Here is the code for my ray casting method (written in C++ and Allegro 5) void renderArrows(Object* i) { float x1 = i->getX() + (i->getWidth() / 2); float y1 = i->getY() + (i->getHeight() / 2); float x2 = screenCentreX; float y2 = ScreenCentreY; float dx = x2 - x1; float dy = y2 - y1; float hypotSquared = (dx * dx) + (dy * dy); float hypot = sqrt(hypotSquared); float unitX = dx / hypot; float unitY = dy / hypot; float rayX = x2 - view->getViewportX(); float rayY = y2 - view->getViewportY(); float arrowX = 0; float arrowY = 0; bool posFound = false; while(posFound == false) { rayX += unitX; rayY += unitY; if(rayX <= 0 || rayX >= screenWidth || rayY <= 0 || rayY >= screenHeight) { arrowX = rayX; arrowY = rayY; posFound = true; } } al_draw_bitmap(sprite, arrowX - spriteWidth, arrowY - spriteHeight, 0); } This was relatively successful. Arrows are displayed in the bottom right section of the screen when objects are located above and left of the screen as if the locations of the where the arrows are drawn have been rotated 180 degrees around the center of the screen. I assumed this was due to the fact that when I was calculating the hypotenuse of the triangle, it would always be positive regardless of whether or not the difference in x or difference in y is negative. Thinking about it, ray casting does not seem like a good way of solving the problem (due to the fact that it involves using sqrt() and a large for loop). Any help finding a suitable solution would be greatly appreciated, Thanks Adam

    Read the article

  • Graphical driver 13.10 ATI RV630

    - by Michael Cephalus
    I started updating the distro from 13.04 to 13.10. Then I got my hands on a Radeon HD 2600. I installed the RV630 compatible Catalystdriver from the official webpage. Then xserver crashed everytime I opened a browser or vlc fx. I took notice that there was no driver listed in configuration underneath. michael@statubtunu:~$ lshw -c video WARNING: you should run this program as super-user. *-display UNCLAIMED description: VGA compatible controller product: RV630 PRO [Radeon HD 2600 PRO] vendor: Advanced Micro Devices, Inc. [AMD/ATI] physical id: 0 bus info: pci@0000:01:00.0 version: 00 width: 64 bits clock: 33MHz capabilities: vga_controller bus_master cap_list configuration: latency=0 resources: memory:d0000000-dfffffff memory:e0500000-e050ffff ioport:1000(size=256) memory:e0000000-e001ffff i installed additional drivers from jockey and the ubuntu softwarecenter ati-driver. though that only made it to crash xserver completely and when i type: michael@statubtunu:~$ sudo startx X.Org X Server 1.14.3 Release Date: 2013-09-12 X Protocol Version 11, Revision 0 Build Operating System: Linux 3.2.0-37-generic i686 Ubuntu Current Operating System: Linux statubtunu 3.11.0-13-generic #20-Ubuntu SMP Wed Oct 23 17:26:33 UTC 2013 i686 Kernel command line: BOOT_IMAGE=/boot/vmlinuz-3.11.0-13-generic root=UUID=8fb2e395-0ea2-4f45-ac66-225696b7ce2c ro quiet splash vt.handoff=7 Build Date: 15 October 2013 09:23:29AM xorg-server 2:1.14.3-3ubuntu2 (For technical support please see http://www.ubuntu.com/support) Current version of pixman: 0.30.2 Before reporting problems, check http://wiki.x.org to make sure that you have the latest version. Markers: (--) probed, (**) from config file, (==) default setting, (++) from command line, (!!) notice, (II) informational, (WW) warning, (EE) error, (NI) not implemented, (??) unknown. (==) Log file: "/var/log/Xorg.0.log", Time: Tue Nov 12 18:50:02 2013 (==) Using system config directory "/usr/share/X11/xorg.conf.d" Initializing built-in extension Generic Event Extension Initializing built-in extension SHAPE Initializing built-in extension MIT-SHM Initializing built-in extension XInputExtension Initializing built-in extension XTEST Initializing built-in extension BIG-REQUESTS Initializing built-in extension SYNC Initializing built-in extension XKEYBOARD Initializing built-in extension XC-MISC Initializing built-in extension SECURITY Initializing built-in extension XINERAMA Initializing built-in extension XFIXES Initializing built-in extension RENDER Initializing built-in extension RANDR Initializing built-in extension COMPOSITE Initializing built-in extension DAMAGE Initializing built-in extension MIT-SCREEN-SAVER Initializing built-in extension DOUBLE-BUFFER Initializing built-in extension RECORD Initializing built-in extension DPMS Initializing built-in extension X-Resource Initializing built-in extension XVideo Initializing built-in extension XVideo-MotionCompensation Initializing built-in extension SELinux Initializing built-in extension XFree86-VidModeExtension Initializing built-in extension XFree86-DGA Initializing built-in extension XFree86-DRI Initializing built-in extension DRI2 Loading extension GLX ERROR: could not insert 'fglrx': No such device (II) [KMS] drm report modesetting isn't supported. (EE) (EE) Backtrace: (EE) 0: /usr/bin/X (xorg_backtrace+0x49) [0xb77780b9] (EE) 1: /usr/bin/X (0xb75d8000+0x1a3e24) [0xb777be24] (EE) 2: (vdso) (__kernel_rt_sigreturn+0x0) [0xb75b540c] (EE) 3: /usr/bin/X (xf86findOption+0x2a) [0xb7681daa] (EE) 4: /usr/bin/X (xf86findOptionValue+0x23) [0xb7681f43] (EE) 5: /usr/bin/X (0xb75d8000+0x7ebfd) [0xb7656bfd] (EE) 6: /usr/bin/X (xf86ProcessOptions+0x37) [0xb7657507] (EE) 7: /usr/lib/xorg/modules/libvbe.so (vbeDoEDID+0xe7) [0xb5eb8647] (EE) 8: /usr/lib/xorg/modules/drivers/vesa_drv.so (0xb5ee7000+0x287c) [0xb5ee987c] (EE) 9: /usr/bin/X (InitOutput+0xb23) [0xb7659c33] (EE) 10: /usr/bin/X (0xb75d8000+0x2a30b) [0xb760230b] (EE) 11: /lib/i386-linux-gnu/libc.so.6 (__libc_start_main+0xf5) [0xb71ba905] (EE) 12: /usr/bin/X (0xb75d8000+0x2a908) [0xb7602908] (EE) (EE) Segmentation fault at address 0x5 (EE) Fatal server error: (EE) Caught signal 11 (Segmentation fault). Server aborting (EE) (EE) Please consult the The X.Org Foundation support at for help. (EE) Please also check the log file at "/var/log/Xorg.0.log" for additional information. (EE) (EE) Server terminated with error (1). Closing log file. This is what comes, but no GUI. Is there any way to deal with this?

    Read the article

  • Single player 'pong' game

    - by Jam
    I am just starting out learning pygame and livewires, and I'm trying to make a single-player pong game, where you just hit the ball, and it bounces around until it passes your paddle (located on the left side of the screen and controlled by the mouse), which makes you lose. I have the basic code, but the ball doesn't stay on the screen, it just flickers and doesn't remain constant. Also, the paddle does not move with the mouse. I'm sure I'm missing something simple, but I just can't figure it out. Help please! Here's what I have: from livewires import games import random games.init(screen_width=640, screen_height=480, fps=50) class Paddle(games.Sprite): image=games.load_image("paddle.bmp") def __init__(self, x=10): super(Paddle, self).__init__(image=Paddle.image, y=games.mouse.y, left=10) self.score=games.Text(value=0, size=25, top=5, right=games.screen.width - 10) games.screen.add(self.score) def update(self): self.y=games.mouse.y if self.top<0: self.top=0 if self.bottom>games.screen.height: self.bottom=games.screen.height self.check_collide() def check_collide(self): for ball in self.overlapping_sprites: self.score.value+=1 ball.handle_collide() class Ball(games.Sprite): image=games.load_image("ball.bmp") speed=5 def __init__(self, x=90, y=90): super(Ball, self).__init__(image=Ball.image, x=x, y=y, dx=Ball.speed, dy=Ball.speed) def update(self): if self.right>games.screen.width: self.dx=-self.dx if self.bottom>games.screen.height or self.top<0: self.dy=-self.dy if self.left<0: self.end_game() self.destroy() def handle_collide(self): self.dx=-self.dx def end_game(self): end_message=games.Message(value="Game Over", size=90, x=games.screen.width/2, y=games.screen.height/2, lifetime=250, after_death=games.screen.quit) games.screen.add(end_message) def main(): background_image=games.load_image("background.bmp", transparent=False) games.screen.background=background_image paddle_image=games.load_image("paddle.bmp") the_paddle=games.Sprite(image=paddle_image, x=10, y=games.mouse.y) games.screen.add(the_paddle) ball_image=games.load_image("ball.bmp") the_ball=games.Sprite(image=ball_image, x=630, y=200, dx=2, dy=2) games.screen.add(the_ball) games.mouse.is_visible=False games.screen.event_grab=True games.screen.mainloop() main()

    Read the article

  • Can a GeneralPath be modified?

    - by Dov
    java2d is fairly expressive, but requires constructing lots of objects. In contrast, the older API would let you call methods to draw various shapes, but lacks all the new features like transparency, stroke, etc. Java has fairly high costs associated with object creation. For speed, I would like to create a GeneralPath whose structure does not change, but go in and change the x,y points inside. path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 10); path.moveTo(x,y); path.lineTo(x2, y2); double len = Math.sqrt((x2-x)*(x2-x) + (y2-y)*(y2-y)); double dx = (x-x2) * headLen / len; double dy = (y-y2) * headLen / len; double dx2 = -dy * (headWidth/headLen); double dy2 = dx * (headWidth/headLen); path.lineTo(x2 + dx + dx2, y2 + dy + dy2); path.moveTo(x2 + dx - dx2, y2 + dy - dy2); path.lineTo(x2,y2); This one isn't even that long. Imagine a much longer sequence of commands, and only the ones on the end are changing. I just want to be able to overwrite commands, to have an iterator effectively. Does that exist?

    Read the article

  • Ray Generation Inconsistency

    - by Myx
    I have written code that generates a ray from the "eye" of the camera to the viewing plane some distance away from the camera's eye: R3Ray ConstructRayThroughPixel(...) { R3Point p; double increments_x = (lr.X() - ul.X())/(double)width; double increments_y = (ul.Y() - lr.Y())/(double)height; p.SetX( ul.X() + ((double)i_pos+0.5)*increments_x ); p.SetY( lr.Y() + ((double)j_pos+0.5)*increments_y ); p.SetZ( lr.Z() ); R3Vector v = p-camera_pos; R3Ray new_ray(camera_pos,v); return new_ray; } ul is the upper left corner of the viewing plane and lr is the lower left corner of the viewing plane. They are defined as follows: R3Point org = scene->camera.eye + scene->camera.towards * radius; R3Vector dx = scene->camera.right * radius * tan(scene->camera.xfov); R3Vector dy = scene->camera.up * radius * tan(scene->camera.yfov); R3Point lr = org + dx - dy; R3Point ul = org - dx + dy; Here, org is the center of the viewing plane with radius being the distance between the viewing plane and the camera eye, dx and dy are the displacements in the x and y directions from the center of the viewing plane. The ConstructRayThroughPixel(...) function works perfectly for a camera whose eye is at (0,0,0). However, when the camera is at some different position, not all needed rays are produced for the image. Any suggestions what could be going wrong? Maybe something wrong with my equations? Thanks for the help.

    Read the article

  • Problem with circular definition in Scheme

    - by user8472
    I am currently working through SICP using Guile as my primary language for the exercises. I have found a strange behavior while implementing the exercises in chapter 3.5. I have reproduced this behavior using Guile 1.4, Guile 1.8.6 and Guile 1.8.7 on a variety of platforms and am certain it is not specific to my setup. This code works fine (and computes e): (define y (integral (delay dy) 1 0.001)) (define dy (stream-map (lambda (x) x) y)) (stream-ref y 1000) The following code should give an identical result: (define (solve f y0 dt) (define y (integral (delay dy) y0 dt)) (define dy (stream-map f y)) y) (solve (lambda (x) x) 1 0.001) But it yields the error message: standard input:7:14: While evaluating arguments to stream-map in expression (stream-map f y): standard input:7:14: Unbound variable: y ABORT: (unbound-variable) So when embedded in a procedure definition, the (define y ...) does not work, whereas outside the procedure in the global environment at the REPL it works fine. What am I doing wrong here? I can post the auxiliary code (i.e., the definitions of integral, stream-map etc.) if necessary, too. With the exception of the system-dependent code for cons-stream, they are all in the book. My own implementation of cons-stream for Guile is as follows: (define-macro (cons-stream a b) `(cons ,a (delay ,b)))

    Read the article

  • Having an issue with the "this" modifier...

    - by user344246
    I have this method in City class. It should create a new city based on the object which the method is applied to: public City newCity(string newCityName, int dX, int dY) { City c=new City(this); //based on a constructor : City(City c){} c.CityName=newCityName; c.NoOfNeighborhoods=1; c.NumOfResidents=0; c.CityCenter.Move(dX,dY); return c; } CityCenter is of type "Point" which has two fields - x,y. the Move method in Point class is ment to change the CityCenter location. It looks like this: public void Move(int dX, int dY) { this.X = x + dX; this.Y = y + dY; } What happens is that the new object,c and the existing City object are both changed. I think that "this" modifier works on the existing object too... How can I take advantage of the Move method without causing this behavior? Note: this is a closed API, so I can only add private methods to the project.

    Read the article

  • Silverlight Cream for December 18, 2010 - 2 -- #1013

    - by Dave Campbell
    In this Issue: Michael Washington, Pete Brown, Robby Ingebretsen, Bill Reiss, Jordan Knight, Mike Taulty, Justin Angel, Jeff Blankenburg. Above the Fold: Silverlight: "Creating the Silverlight View Model (MVVM) Control: Calendar Icon" Michael Washington WP7: "United Nations News for Windows Phone 7" Justin Angel Silverlight, WP7/WPF: "CameraPanel: A Parallax Panel for Silverlight, WP7 or WPF" Robby Ingebretsen Shoutouts: Michael Scherotter produced a Silverlight Webcam photo app that he's providing as a free install: A Free Webcam Photo Application in Silverlight From SilverlightCream.com: Creating the Silverlight View Model (MVVM) Control: Calendar Icon Michael Washington has a stunning Calendar Control/Icon up on his blog... walking through how he built it and how you can easily use it in your Silverlight or WP7 app. Strategies for Improving INotifyPropertyChanged in WPF and Silverlight Pete Brown takes a look at INPC and some of the ways this is dealt with to avoid some of the tedius code-reuse errors we all make. CameraPanel: A Parallax Panel for Silverlight, WP7 or WPF Robby Ingebretsen gives up the code for that cool panel he's got on his homepage where the small panels move about seemingly in space. Writing a Windows Phone 7 game? Have a fallback plan Bill Reiss, who has a great WP7 game up - Popper 2 - has a very well-thought-out post up about WP7 'indie' games and the future thereof... great comments from reader/authors as well Automatic template selection – marrying a view to a view model Jordan Knight has the 2nd post of his series on MVVM up... he's talking about it in context of their XamlingCore, but concepts are all good. Rebuilding the PDC 2010 Silverlight Application (Part 5) Mike Taulty's next episode in describing the development of the PDC10 app he wrote is up ... again lots of Blend goodness in this one where he's adding buttons to let the user (us) download whatever is available for the chosen session. United Nations News for Windows Phone 7 In a munificent gesture, Justin Angel not only made his United Nation News app free on the marketplace, but he's posted the source to CodePlex! Justin had sent me a XAP a couple weeks ago, but for some reason, I can no longer sideload so wasn't able to try it until now... too cool, Justin! What I Learned In WP7 – Issue #6 Jeff Blankenburg has his latest "What I learned in WP7" tip up ... and this is one about the marketplace written by someone that's been there and back a few times... Stay in the 'Light! Twitter SilverlightNews | Twitter WynApse | WynApse.com | Tagged Posts | SilverlightCream Join me @ SilverlightCream | Phoenix Silverlight User Group Technorati Tags: Silverlight    Silverlight 3    Silverlight 4    Windows Phone MIX10

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >