2d

Figure out what keys a player is pressing based on relative velocity and angle

你离开我真会死。 提交于 2020-01-15 03:39:06
问题 I have two pieces of information: a 2D-vector representing velocity relative to a grid and an angle (180 to negative 180 degrees) representing the player's view-angle also relative to that grid, and I am from that trying to figure out what keys (W, A, S, D) the player is pressing with this information. The thing that is giving me troubles are the fact that the player moves in respect to the view-angle. So if the player is looking 35 degrees relative to our grid and pressing forward (W), the

libGDX Coordinate System

有些话、适合烂在心里 提交于 2020-01-14 03:05:17
问题 I'm trying to properly configure my Camera and Sprite s in libGDX to show up in a 2D coordinate system properly with the origin at the bottom left hand corner. I set up my Camera like this: cameraWidth = Gdx.graphics.getWidth(); cameraHeight = Gdx.graphics.getHeight(); camera = new OrthographicCamera(1, cameraHeight/cameraWidth); And I set up my Sprite s like this: sprite.setOrigin(sprite.getWidth()/2, sprite.getHeight()/2); sprite.setScale(scale); sprite.setPosition(startX,startY); My

Algorithm to find all points on a 2D grid some distance away from another point

喜你入骨 提交于 2020-01-13 09:32:34
问题 I have some point on a 2D grid (x, y) and I need to find all points that are n distance away from that point. The way I'm measuring distance is by using the distance formula between the two points. Anyone know how to do this? Edit: Just for reference, what I'm trying to do is to write some AI path finding that will maintain some distance away from a target in a system that uses grid based locations. Currently I'm using A* path finding, but I'm not sure if that matters or makes a difference

2D Elastic Ball Collision Physics

为君一笑 提交于 2020-01-12 16:10:00
问题 I am making a program that involves elastic ball physics. I have worked out all of the maths for collision against walls and stationary objects, but I cannot figure out what happens when two moving balls collide. I have mass and velocity (x and y velocity to be exact, but velocity of each ball and their direction will do) and would like the formulae for those. Remember - this is a perfectly elastic collision - so no spinning balls, etc. 回答1: This wikipedia article provides a formula to

2D Elastic Ball Collision Physics

这一生的挚爱 提交于 2020-01-12 16:07:14
问题 I am making a program that involves elastic ball physics. I have worked out all of the maths for collision against walls and stationary objects, but I cannot figure out what happens when two moving balls collide. I have mass and velocity (x and y velocity to be exact, but velocity of each ball and their direction will do) and would like the formulae for those. Remember - this is a perfectly elastic collision - so no spinning balls, etc. 回答1: This wikipedia article provides a formula to

Unprojecting 2D Screen Coordinates to 3D Coordinates

☆樱花仙子☆ 提交于 2020-01-12 08:52:30
问题 I was wondering how I would go about mapping 2D screen coordinates to a 3D world (specifically the xz plane) knowing: -position of the camera -equation of the screen plane -equation of the xz plane All I want to do is have the land on the xz plane light up when I hover the mouse over it. Any help is greatly appreciated! Thanks! 回答1: If your world is rotated and shifted such that the camera is at x=y=z=0 (world coordinates), the world z coordinate increases away from the viewer (into the

Unprojecting 2D Screen Coordinates to 3D Coordinates

风流意气都作罢 提交于 2020-01-12 08:52:22
问题 I was wondering how I would go about mapping 2D screen coordinates to a 3D world (specifically the xz plane) knowing: -position of the camera -equation of the screen plane -equation of the xz plane All I want to do is have the land on the xz plane light up when I hover the mouse over it. Any help is greatly appreciated! Thanks! 回答1: If your world is rotated and shifted such that the camera is at x=y=z=0 (world coordinates), the world z coordinate increases away from the viewer (into the

Rendering multiple 2D images in OpenGL-ES 2.0

末鹿安然 提交于 2020-01-11 06:49:07
问题 I am new to OpenGL, and trying to learn ES 2.0. To start with, I am working on a card game, where I need to render multiple card images. I followed this http://www.learnopengles.com/android-lesson-four-introducing-basic-texturing/ I have created a few classes to handle the data and actions. MySprite holds the texture information, including the location and scale factors. Batcher draws all the sprites in one go. It is rough implementation. ShaderHelper manages creation of shaders and linking

use super.paintComponent(g) or getGraphics() in java

余生长醉 提交于 2020-01-11 06:44:13
问题 i' m little bit confused about few things: Example code,that shows my problem,this isn't compilable // image private BufferedImage image; private Graphics2D graphic; private changeImage; . . . //thread loop while (running) { . . . render(); Graphics showGraphic = getGraphics(); showGraphic.drawImage(image, 0, 0, null); showGraphic.dispose(); } public void render(){ if(changeImage == 1) graphic.drawImage(ImageLoader.TREE, 0, 0, null); else if(changeImage == 2){ graphic.drawImage(ImageLoader

Why does use of pens with dash patterns cause huge (!) performance degredation in WPF custom 2D drawing?

喜你入骨 提交于 2020-01-10 19:55:30
问题 Hope anyone can shed light on this so I can use pens with dash patterns? I am writing a scrollable chart (a Panel inside ScrollViewer that implements IScrollInfo ) in WPF using DrawingVisual 's DataContext.Draw X . I have several thousand DrawingVisual s that get scrolled by using TranslateTransform on the Panel that hosts them. I implemented a grid by placing a Panel on top of it and drawing simple horizontal lines from one edge to the other using DataContext.DrawLine(pen, new Point(0, y),