2d

Java - 2D array checking diagonal number board

∥☆過路亽.° 提交于 2019-12-06 09:03:13
Currently I'm working on a program that generates random 0's and 1's in a 8x8 2D array board. What I have to do is check whether or not if all the numbers on the diagonal are the same (starting from the corners, not just any diagonals) example: int[][] array = { {0, 0, 0, 0, 0, 0, 0, 1}, {0, 0, 1, 0, 1, 0, 1, 0}, {0, 0, 0, 0, 1, 1, 1, 0}, {0, 0, 0, 0, 1, 1, 1, 0}, {0, 0, 1, 1, 0, 1, 1, 0}, {0, 0, 1, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 0}, {1, 0, 0, 1, 1, 1, 1, 0} }; So if by chance all the numbers starting from the top left corner (0,0),(1,1)...(7,7) are all either 0's or 1's then I have to

Unity LookAt 2d Equivalent

為{幸葍}努か 提交于 2019-12-06 08:54:25
I'm creating a tank fighting 2D game top-down in Unity 3D in the 2D perspective active. My axises are X and Y (defaulted) and I'm trying to create a homing missile My missile code is code is: var enemyName :String; // which enemy does this shot seeks private var target :GameObject; var speed :float = 100; private var timeToTarget:float; function Start () { timeToTarget = Mathf.Abs(speed); if (timeToTarget<=0) { timeToTarget=150; } target = GameObject.Find(enemyName); Destroy(this.gameObject, timeToDie); myTransform = transform; } function Update () { rorate2target(); follow(); } function

XNA 2D mouse picking

青春壹個敷衍的年華 提交于 2019-12-06 08:43:25
I'm working on a simple 2D Real time strategy game using XNA. Right now I have reached the point where I need to be able to click on the sprite for a unit or building and be able to reference the object associated with that sprite. From the research I have done over the last three days I have found many references on how to do "Mouse picking" in 3D which does not seem to apply to my situation. I understand that another way to do this is to simply have an array of all "selectable" objects in the world and when the player clicks on a sprite it checks the mouse location against the locations of

MPI datatype for 2 d array

三世轮回 提交于 2019-12-06 08:42:36
问题 I need to pass an array of integer arrays (basically a 2 d array )to all the processors from root.I am using MPI in C programs. How to declare MPI datatype for 2 d array.and how to send the message (should i use broadcast or scatter) 回答1: You'll need to use Broadcast, because you want to send a copy of the same message to every process. Scatter breaks up a message and distributes the chunks between processes. As for how to send the data: the HIndexed datatype is for you. Suppose your 2d array

three.js skydome with gradient

坚强是说给别人听的谎言 提交于 2019-12-06 08:09:27
I would like to add a sphere with a 2d gradient as texture to create a skydome. I read that in openGL this is often solved by rendering the skybox without depthtest in an additonal pass. I disabled depthTest on my sphere so everything else is drawn in front of it, it's kinda giving me the disired effect but depending on the camera angle it clips through other objects in my scene. I was looking at several examples which make use of THREE.EffectComposer and a second scene, I may be completely after the wrong thing here but I think that could solve this. The thing is I havent ever touched the

java applet: is there a simple way to draw and erase in a two-layered 2D scene?

久未见 提交于 2019-12-06 07:21:28
问题 I have an applet which displays some data using circles and lines. As the data continually changes, the display is updated, which means that sometimes the circles and lines must be erased, so I just draw them in white (my background color) to erase them. (There are a lot of them, so erasing everything and then recomputing and redrawing everything except the erased item would be a horribly slow way to erase a single item.) The logic of the situation is that there are two layers that need to be

Retrieve 2D co-ordinate from a 3D point on a 3D plane

微笑、不失礼 提交于 2019-12-06 06:17:36
I have a point a point (x, y, z) that is on a plane defined by ax+by+cz+d=0. I'm trying to figure out what the (x', y') relative to the plane, where it has a starting point of (x0, y0, z0) and the x'-axis is defined by (1,0) and the y'-axis is defined by (0,1). My major goal is to have the mouse click on a surface, and know the 2D co-ordinates on a particular surface. I've managed to intersect the ray onto a plane quite trivially. As a side-note, I'm using DirectX 9 - my familiarity with matrix/vector math is limited by the APIs provided to me through the D3DX libraries. One thought I had was

Passing a dynamic 2D array from C++ to Fortran and back

五迷三道 提交于 2019-12-06 05:24:06
Passing a fixed 2D array between C++ and Fortran works fine, however not so with the program I have written to pass a 2D dynamic array from C++ to Fortran. C++ side extern "C" {void array2d_(double **, int *, int *); } using namespace std; int main() { double **array; int nx=3; int ny=2; int i,j; cout << "Passing dynamic array from C to Fortran\n"; array = (double **) malloc(nx * sizeof(double *)); if(array == NULL) { fprintf(stderr, "out of memory\n"); exit; } for(i = 0; i < nx; i++) { array[i] = (double *) malloc(ny * sizeof(double)); if(array[i] == NULL) { fprintf(stderr, "out of memory\n")

bounding box of n glyphs, given individual bboxes and advances

左心房为你撑大大i 提交于 2019-12-06 05:21:42
For specific reasons, I'm implementing my own font rendering, and an algorithm to compute the bounding box of a text by using bounding boxes of single glyphs, together with the respective advance, is needed. For clarification see this illustration : For every of these N glyphs is given the relative bbox relative to the origin (xmin, xmax, ymin, ymax), and the advance (pseudocode): int xmin[N], xmax[N], ymin[N], ymax[N], adv[N]; I will give the answer myself if noone bites. For the general case you won't be able to accurately measure a string using just the glyph bounding box and the advance

Efficient algorithm for collisions in 2D game?

∥☆過路亽.° 提交于 2019-12-06 05:17:42
问题 I'm programming a Bomberman in Java following a tutorial (this is my first game). The tutorial suggests the following code for detecting collisions. for (int p=0; p<entities.size(); p++) { for (int s=p+1; s<entities.size(); s++) { Entity me = (Entity) entities.get(p); Entity him = (Entity) entities.get(s); if (me.collidesWith(him)) { me.collidedWith(him); him.collidedWith(me); } } By now, entities is an array list containing the enemies and the player. As I want to also detect the player