2d

Calculate a vector from the center of a square to edge based on radius

六眼飞鱼酱① 提交于 2019-11-30 23:33:51
Given a square (described by x, y, width, height) and an angle (in radians) I need to calculate a vector that originates at the squares centre and terminates at the point that collides with the edge of the square at the given angle. I'm really most interested in the point it collides at so if that would make calculation more efficient let me know. Can this be generalized to Rectangles? How about polygons in general? The vector will be center + (cos(angle), sin(angle))*magnitude . Given that you want to intersect this with a square, you need to determine magnitude. You can get that with a

WPF real-time rendering

妖精的绣舞 提交于 2019-11-30 20:20:10
问题 I'm designing a game and thinking about using WPF for making a simple prototype of the basic gameplay. Is it possible to render basic 2d-graphics in WPF in real-time? By basic graphics I mean simple shapes such as lines, circles, etc. By "real-time" I mean things are rendered based on parameters such as velocity, acceleration, etc. that changes depending on player input - which I assume means I can't use storyboards for the animations. Thanks 回答1: Check out the previous question High

c++ reading in text file into vector<vector> then writing to vector or array depending on first word in internal vector

纵饮孤独 提交于 2019-11-30 19:14:24
问题 this is a progression from the question I posted c++ program for reading an unknown size csv file (filled only with floats) with constant (but unknown) number of columns into an array . Im now moving onto the real application where I read in a file like: MESH2D MESHNAME "default coverage" NUM_MATERIALS_PER_ELEM 1 E4Q 1 19 20 14 16 2 E4Q 2 17 16 15 23 2 E4Q 3 22 15 14 21 2 E4Q 4 4 3 21 20 1 E4Q 5 6 20 19 7 1 E4Q 6 18 17 10 9 1 E4Q 7 17 23 12 11 1 E4Q 8 7 19 18 8 1 E4Q 9 22 1 13 23 1 E3T 10 14

WPF: Resizing a circle, keeping the center point instead of TopLeft?

雨燕双飞 提交于 2019-11-30 19:11:45
I'd like to resize a circle on my canvas with the help of a slider. This circle can be moved around on the canvas by some drag&drop stuff I did in code behind, so its position is not fixed. I have bound the slider's value to an ellipse's height and width. Unfortunately, when I use the slider, the circle gets resized with its top left point (actually the top left point of the rectangle it's sitting in) staying the same during the operation. I would like to resize it with its center point being constant during the operation. Is there an easy way to do this in XAML? BTW, I already tried

Large scrolling background in OpenGL ES

北慕城南 提交于 2019-11-30 18:48:37
问题 I am working on a 2D scrolling game for iPhone. I have a large image background, say 480×6000 pixels, of only a part is visible (exactly one screen’s worth, 480×320 pixels). What is the best way to get such a background on the screen? Currently I have the background split into several textures (to get around the maximum texture size limit) and draw the whole background in each frame as a textured triangle strip. The scrolling is done by translating the modelview matrix. The scissor box is set

Determine color of a pixel in a winforms application

放肆的年华 提交于 2019-11-30 18:10:52
问题 I'd like to be able to determine the backgroundcolor of a winform at a certain point on the screen, so I can take some action depending on that particular color. Sadly the System.Drawing library doesn't seem to specify a method that enables me to do so. How should I then determine the color at a certain point? 回答1: Use that : using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; using System.Drawing; namespace

Calculate a vector from the center of a square to edge based on radius

坚强是说给别人听的谎言 提交于 2019-11-30 18:06:11
问题 Given a square (described by x, y, width, height) and an angle (in radians) I need to calculate a vector that originates at the squares centre and terminates at the point that collides with the edge of the square at the given angle. I'm really most interested in the point it collides at so if that would make calculation more efficient let me know. Can this be generalized to Rectangles? How about polygons in general? 回答1: The vector will be center + (cos(angle), sin(angle))*magnitude . Given

Having the Background or Camera “Scroll” based on charcter position

蹲街弑〆低调 提交于 2019-11-30 17:07:18
I'm working on an RPG game that has a Top-Down view. I want to load a picture into the background which is what the character is walking on, but so far I haven't figured out how to correctly have the background redraw so that it's "scrolling". Most of the examples I find are auto scrolling. I want the camera to remained centered at the character until you the background image reaches its boundaries, then the character will move without the image re-drawing in another position. Your question is a bit unclear, but I think I get the gist of it. Let's look at your requirements. You have an

Creating a 3D effect from a 2D image

一曲冷凌霜 提交于 2019-11-30 16:42:18
I have a random 2D image. I would like to be able to present the image in 3D. This doesn't have to be very detailed, even if the image were arbitrarily broken into layers like a pop-up cutout from a children's book. The goal would be that a given image would look normal when directly viewed but that if a viewer were to move/tilt left, right, up, down there would be a 3d effect. This is similar but not exactly the same as this question here: How to create 3D streoscopic images using MATLAB with image tool? This is complete over-kill: http://make3d.cs.cornell.edu/ And this is probably on the

Foreach and 2D Array in PHP

邮差的信 提交于 2019-11-30 16:29:18
$mainMenu['Home'][1] = '/mult/index.php'; $mainMenu['Map'][1] = '/mult/kar.php'; $mainMenu['MapA'][2] = '/mult/kara.php'; $mainMenu['MapB'][2] = '/mult/karb.php'; $mainMenu['Contact'][1] = '/mult/sni.php'; $mainMenu['Bla'][1] = '/mult/vid.php'; This is a menu, 1 indicates the main part, 2 indicates the sub-menu. Like: Home Map -MapA -MapB Contat Bla I know how to use foreach but as far as I see it is used in 1 dimensional arrays. What I have to do in the example above? You would need to nest two foreach BUT, there is nothing about your data structure that easily indicates what is a sub-item.