Search Results

Search found 4 results on 1 pages for 'manderin87'.

Page 1/1 | 1 

  • Move projectile in direction the gun is facing

    - by Manderin87
    I am attempting to have a projectile follow the direction a gun is facing. When using the following code I am unable to make the projectile go in the right direction. float speed = .5f; float dX = (float) -Math.cos(Math.toRadians(degree)) * speed; float dY = (float) Math.sin(Math.toRadians(degree)) * speed; Can anyone tell me what I am doing wrong? The degree is the direction the gun is facing in degree's.

    Read the article

  • Polygon is rotating too fast

    - by Manderin87
    I am going to be using a polygon collision detection method to test when objects collide. I am attempting to rotate a polygon to match the sprites rotation. However, the polygon is rotating too fast, much faster than the sprite is. I feel its a timing issue, but the sprite rotates like it is supposed to. Can anyone look at my code and tell me what could be causing this issue? public void rotate(float x0, float y0, double angle) { for(Point point : mPoints) { float x = (float) (x0 + (point.x - x0) * Math.cos(Utilities.toRadians(angle)) - (point.y - y0) * Math.sin(Utilities.toRadians(angle))); float y = (float) (y0 + (point.x - x0) * Math.sin(Utilities.toRadians(angle)) + (point.y - y0) * Math.cos(Utilities.toRadians(angle))); point.x = x; point.y = y; } } This algorithm works when done singly, but once I plug it into the update method the rotation is too fast. The Points used are: P1 608, 368 P2 640, 464 P3 672, 400 Origin x0 is: 640 400 The angle goes from 0 to 360 as the sprite rotates. When the codes executes the triangle looks like a star because its moving so fast. The rotation is done in the sprites update method. The rotation method just increases the sprites degree by .5 when it executes. public void update() { if(isActive()) { rotate(); mBounding.rotate(mPosition.x, mPosition.y, mDegree); } }

    Read the article

  • Bitmap rotation jitter around pivot

    - by Manderin87
    I am working on a asteriods clone and I have the ship graphic loaded as a 96x96 bitmap. When the player rotates the ship I rotate the bitmap by degree (float). rotation function: if(m_Matrix == null) { m_Matrix = new Matrix(); } else { m_Matrix.reset(); } m_Matrix.setRotate(degree, m_BaseImage.getWidth() / 2, m_BaseImage.getHeight() / 2); m_RotatedImage = Bitmap.createBitmap(m_BaseImage, 0, 0, m_BaseImage.getWidth(), m_BaseImage.getHeight(), m_Matrix, true); draw function: m_Paint.setAntiAlias(true); m_Paint.setFilterBitmap(true); m_Paint.setDither(true); canvas.drawBitmap(m_RotatedImage, (int) posX - m_RotatedImage.getWidth() / 2, (int) posY - m_RotatedImage.getHeight() / 2, m_Paint); When the bitmap is drawn, the bitmap jitters slightly around the pivot. Can anyone fix or tell me why the bitmap is jittering around the pivot? It needs to be smooth.

    Read the article

  • Roguelike FOV problem

    - by Manderin87
    I am working on a college compsci project and I would like some help with a field of view algorithm. I works mostly, but in some situations the algorithm sees through walls and hilights walls the player should not be able to see. void cMap::los(int x0, int y0, int radius) { //Does line of sight from any particular tile for(int x = 0; x < m_Height; x++) { for(int y = 0; y < m_Width; y++) { getTile(x,y)->setVisible(false); } } double xdif = 0; double ydif = 0; bool visible = false; float dist = 0; for (int x = MAX(x0 - radius,0); x < MIN(x0 + radius, m_Height); x++) { //Loops through x values within view radius for (int y = MAX(y0 - radius,0); y < MIN(y0 + radius, m_Width); y++) { //Loops through y values within view radius xdif = pow( (double) x - x0, 2); ydif = pow( (double) y - y0, 2); dist = (float) sqrt(xdif + ydif); //Gets the distance between the two points if (dist <= radius) { //If the tile is within view distance, visible = line(x0, y0, x, y); //check if it can be seen. if (visible) { //If it can be seen, getTile(x,y)->setVisible(true); //Mark that tile as viewable } } } } } bool cMap::line(int x0,int y0,int x1,int y1) { bool steep = abs(y1-y0) > abs(x1-x0); if (steep) { swap(x0, y0); swap(x1, y1); } if (x0 > x1) { swap(x0,x1); swap(y0,y1); } int deltax = x1-x0; int deltay = abs(y1-y0); int error = deltax/2; int ystep; int y = y0; if (y0 < y1) ystep = 1; else ystep = -1; for (int x = x0; x < x1; x++) { if ( steep && getTile(y,x)->isBlocked()) { getTile(y,x)->setVisible(true); getTile(y,x)->setDiscovered(true); return false; } else if (!steep && getTile(x,y)->isBlocked()) { getTile(x,y)->setVisible(true); getTile(x,y)->setDiscovered(true); return false; } error -= deltay; if (error < 0) { y = y + ystep; error = error + deltax; } } return true; } If anyone could help me make the first blocked tiles visible but stops the rest, I would appreciate it. thanks, Manderin87

    Read the article

1