FAQ Database Discussion Community


How does Matrix.postScale( sx, sy, px, py) work?

android,matrix,2d
First read Taig's question Taig said: When calling Matrix.postScale( sx, sy, px, py ); the matrix gets scaled and also translated (depending on the given point x, y). That predestines this method to be used for zooming into images because I can easily focus one specific point. The android doc...

CSS transitions - rotateX is just changing the size of my element

css,rotation,size,2d,transitions
I have a problem with CSS transitions. I have two buttons on my website (here) which are supposed to be pushed back on the bottom of it when the mouse is holding down on it just like on the Windows 8 start menu. Instead, what's happening is is that it...

Wrong repositioning circle after collision with segment with a vector algorythm

math,vector,2d,collision-detection
In a 2D game, i'm trying to repositionate a circle after it passed through a segment. Taking the picture as example situation, i need to reposition back the circle so that B will become the tangent point on the circle. The informations that i have are: x,y of the circle...

buttons only react to clicks/touches when clicking/touching to the right of them

unity3d,click,touch,2d,mouse
I'm making a 2D game in Unity3D for android. Right now I'm making buttons. And this buttons does not react clicks/touched properly. I've got same issue with mouse clicks and touches both. Every button has trigger boxcollider with a same size as an object. BUT buttons react only when I...

Need help Implementing maze into 2d array c++

c++,arrays,2d,maze
So Im creating a treasure hunting game where the user moves through a maze with hidden health and traps. The goal is to find the treasure without dying. However, I need to create a map and I have a map I generated. I was wondering if there was a way...

How to check collision on 2D map in SFML?

c++,arrays,2d,collision-detection,sfml
I have one RectangleShape for wall and I draw this one object for every "1" on my 2D map: int map[5][8] = { { 1, 1, 1, 1, 1, 1, 1, 1 }, { 1, 0, 0, 0, 0, 0, 0, 1 }, { 1, 0, 1, 0, 1, 1,...

How can I make this HTML5 canvas progress bar fill from the bottom up instead of the top down?

javascript,css,html5,canvas,2d
I am using this example to build my own progress bar that will keep track of the players fuel level in a game I am making. HTML <h1>Canvas Progress Bar Test</h1> <form> <ul> <li> <input type="radio" name="direction" id="vertical" value="vertical" checked /> <label for="vertical">Vertical</label> <input type="radio" name="direction" id="horizontal" value="horizontal" /> <label...

Copying and comparing individual element from 2D array to another array in C

c,arrays,2d
char first_array[5][4] = {"aaa","bbb","ccc","ddd","eee"}; char second_array[1][4]; How would I copy, for example, the third element in first_array ("ccc") and save it to second_array? The syntax below is clearly wrong, but this is what I'm asking for: second_array[0] = first_array[2]; Also, after copying, I also want to know how to compare...

How can I make a sprite move downward in a 2D space?

c#,unity3d,2d
I am trying to make a game object in unity just go vertically down. I have tried using GameObject.transform() and things like that. All I am asking is, if anyone can give me something to look into such as which method or class I would use to make a 2D...

what is the better practice to allocate 2d array in C

c,arrays,2d
I am writing a program for MD simulation, in which I need to use dynamically allocated 2D array. For performance reasons, I want the memory the the 2D array is a consecutive chunk. There are two ways I know to do this Use VLA in C99. size_t rows, cols; int...

Moving a picture box in timer C# Winforms

c#,winforms,timer,2d,picturebox
Ok so please keep answers very direct and i must say i am very new to C#, i don't know a lot of stuff. Without further adieu my problem. I am trying to move a picture box horizontally across the screen on a timer.The timer must go infinitely. I have...

OpenGL - How to draw multiple different 2D shapes using pop-up menu?

opengl,2d,glut,freeglut
I'm trying to make a simple openGL application which creates shapes using mouse clicks. The shape required is selected using a pop-up menu opened using the right mouse button. Currently I have rectangle working and also a simple paint-esque function using points. They disappear once redrawn but that's a problem...

Problems with [ ][ ] and if-statement

java,arrays,if-statement,for-loop,2d
I have an error in my program, which i'll state below: int[][]image = { {0,0,2,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,5,5,5,5,5,5,5,5,0,0}, {0,0,5,5,5,5,5,5,5,5,0,0}, {0,0,5,5,5,5,5,5,5,5,0,0}, {0,0,5,5,5,5,5,5,5,5,0,0}, {0,0,5,5,5,5,5,5,5,5,0,0}, {0,0,5,5,5,5,5,5,5,5,0,0}, {0,0,5,5,5,5,5,5,5,5,0,0}, {0,0,5,5,5,5,5,5,5,5,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}//assume this rectangular image }; int[][]smooth = new int[image.length][image[0].length]; //new array equal to image[][] Notice image[][]. It is a 2D...

Convert a 2d double array to 2d double arraylist

java,arrays,arraylist,2d
I have a 2D Double array that is expanding and I am not sure of its final size therefore I want to convert it to a 2d arraylist but not sure how to do this I tried to define the array list first and use addAll(Array) method but it doesn't...

Blurring in PyGame

python,graphics,pygame,2d
I'm working on a short intro in PyGame, and I need to blur some static lines. After two days of searching, I can't find anything. Does PyGame have a built-in method to blur a shape or surface? Will I need to do it manually? What would be the best way...

Adapting a command line-driven turn-based rpg to swing's event-driven paradigm

java,swing,user-interface,2d
Background: For the past few months, I've been working on a turn-based RPG in my free time in Java. I have only been programming for around a year, so my expertise is mostly limited to command line applications and object-oriented programming principles that I learned in elementary CS classes. Development...

Drawing a Line - Maximum Point

java,2d,line,coordinates
I drew a line that is at an angle based on a slider. I am trying to make the line's end Y coordinate a certain number (let's say 300), even if it is at an angle. Any ideas on how to do this? Here is the work on my line...

How to draw 2D matrix of squares on iOS?

ios,swift,graphics,sprite-kit,2d
What is the best way how to draw a matrix of squares on iOS using SpriteKit? I am complete iOS beginner and I'm not sure what is the correct approach. I was thinking creating a sprite representing a picture of a square and than add that sprite several times to...

JavaFX Line segment width

java,javafx,2d,line
I have some code which responds to key presses, and draws points and line segments correspondingly. However, the width of the line segments seems to alternate, even though I don't touch the line stroke width in the code. I'm wondering why this is happening. Here is the code: import javafx.application.Application;...

2D overlay on top of 3D plane with texture

three.js,2d,overlay
I am trying to draw a 2D square on top of my plane but I can not get to a good solution. So far I just draw 3D lines on top of the plane. geometry = new THREE.Geometry(); geometry.vertices.push(new THREE.Vector3(HANDLES[0].position.x, HANDLES[0].position.y, HANDLES[0].position.z)); geometry.vertices.push(new THREE.Vector3(HANDLES[0].position.x, HANDLES[1].position.y, HANDLES[0].position.z)); geometry.vertices.push(new THREE.Vector3(HANDLES[0].position.x, HANDLES[1].position.y, HANDLES[1].position.z));...

Accurate Circular Orbit Equation in java

java,2d,game-physics,gravity,orbital-mechanics
public void move(){ double angle; for(int i = 0; i < planets.size(); i++){ if(Math.abs(Math.sqrt(Math.pow(ship.locX - (planets.get(i).locX + planets.get(i).radi), 2) + Math.pow(ship.locY - (planets.get(i).locY + planets.get(i).radi), 2))) < planets.get(i).gravrange){ //Distance formula between spaceship and planets to determine whether the ship is within the influence of the planet. angle = ((Math.atan2((planets.get(i).locX +...

2D perspective transform in JavaScript

javascript,geometry,2d,spatial,perspective
Looking for a code example of how to calculate (accurately) the dimensions of a rectangle from a top down view (90 degrees) at a particular angle. e.g. I have a rectangle of 1200mm x 2000mm How would i determine the new perspective measurements of the rectangle if it was angled...

freopen only prints one line when printf prints as much lines as i want (C++)

c++,opengl,2d
So i wanted to print a few lines of GL's Vertex2d coordinates into a file and i used this: { //namespace (for cout + cin) using namespace std; int p; //number of sides //body double r,d=3/4.0; cout << "input side count" <<endl; cin >> p; cout << "input radius" <<endl;...

How to do two ifs at once

java,2d
I have a Background Image and a Hero Image. In the Background, at 520(x) and 260(y) is a house. I don't want my Hero to be able to "pass through" the house, but my methods aren't working. This is what I have done so far (I don't know if it...

Python Sorting 2D List with custom Key

python,list,sorting,2d
So I have a 2D list and want to sort it using a second file of keys. Does anyone know how I would go about doing that? Heres an example input: And here is an example input file: first_nm,last_nm,gender,cwid,cred_hrs,qual_pts,gpa John,Roe,M,44444444,40,150,3.75 Jane,Roe,F,66666666,100,260,2.6 John,Doe,M,22222222,50,140,2.8 Jane,Doe,F,88888888,80,280,3.5 Penny,Lowe,F,55555555,40,140,3.5 Lenny,Lowe,M,11111111,100,280,2.8 Denny,Lowe,M,99999999,80,260,3.25 Benny,Lowe,M,77777777,120,90,0.75 Jenny,Lowe,F,33333333,50,90,1.8 Zoe,Coe,F,0,50,130,2.6 Here...

How find 1d array in 2d array

javascript,arrays,search,2d
I have a 2d array(3*3) and a 1d(3) array. And now I want to find 1d array in 2d array in columns and rows and order is not important. i.e. A=[ [0,1,2], [3,4,5], [6,7,8] ]; and my 1d array is like: t=[7,4,1]; I want when search second array(1d) in 2d...

What is the best 2d graphic library for javascript?

javascript,2d,graphic
I want to make simple 2d game using javaScript. What should i know before i start? I'm a c# programmer and I don't have much experience with js. Is there any design patterns should i know about?

Is there a better way to create this kind of swipe inside Unity?

unity3d,2d,swipe,coroutine
I'm making a swipe for my 2D game and the code below handles the horizontal swipe of the game. Think of it like a horizontal swipe (Android-like swipe) between a line of doors: using UnityEngine; using System.Collections; public class DoorController : MonoBehaviour { public Camera mainCamera; private float speed; private...

Number of subarray data types for exchanging 2D halos in 3D process decomposition in MPI

c,3d,parallel-processing,2d,mpi
Assume a global cube of dimensions GX*GY*GZ which is decomposed using 3D Cartesian Topology into 3D cubes of sizes PX*PY*PZ on each process. Adding Halos for exchange of data this becomes (PX+2)*(PY+2)*(PZ+2). Assuming we use the Subarray data type for 2D halo exchange - do we need to define 12...

how to define a 2d discrete delta function that can take array input in matlab

arrays,matlab,2d,delta
function y = dd2(x1,x2) y=0; if x1==0 && x2==0 y=1; end This would not work because the input cannot be an array. I hope to make it can work for an array X of 1*m, and an array Y of 1*n so when you dd2(X,Y) it creates a m*n matrix...

Initializing a 2D array of union type (ints or chars)

c,arrays,matrix,2d,unions
So I'm trying to create a 2d array of size rows x columns. I allocated space for it (or at least I think) and now I am trying to initialize it or at least test it to see if it can hold values. However I get an incompatible type error...

Render an SVG with filter effects to PNG

svg,graphics,2d,skia
I would like to render an SVG I've created to a hi-res (600 DPI) PNG. This SVG has filter effects, specifically gaussian blur. Ideally rendering could be done via the command line. I know the SVG is renderable because you can open it in Chrome/Chromium and the output I'd like...

Every way to get textures, WebGL

javascript,2d,textures,webgl
I was wondering if there was any other way to get textures in WebGL other than the standard Image() constructor. Specifically I would like to make a texture using the data from a tag in html, but I would also like to see other ways....

2 problems when workin with sprites on Unity3D

c#,unity3d,2d,sprite
I need to replace the sprite of a face down card for another sprite (of a face up card). This is the C# script attached to the face down card: using UnityEngine; using System.Collections; public class Entra : MonoBehaviour { public float velocidadDeRotacion = 100.0f; public Sprite CartaBase; public Sprite...

My code is making duplicate copies of 2D array elements. What is wrong in the code?

c++,arrays,sorting,2d
My code basically checks a particular triangle in a 3xn array and orders it in ascending order, triangle by triangle. But the problem I am facing right now is, my code is apparently creating duplicates and overwriting data. Please help me figure out the bug. Cheers. #include<iostream> #include<conio.h> #include<stdio.h> #include<fstream>...

Java - Draw'ing outside frame

java,performance,graphics,2d,game-engine
I am developing a 2d game; I am currently developing a system of movement of the camera on the map, I used the following method: my camera has own coordinates - x,y; I have ArrayList with all my sprites for map with their coords from 0 to mapSize, every sprite...

Why is my for only working on the first variable?

java,arrays,for-loop,input,2d
The code i wrote works fine if i type in COSC 1337 but once i type any of the other elements in the array it will display my error message instead of the time and date what am i doing wrong? import java.util.Scanner; public class Schedule { public static void...

How to make movable character in maze with C++

c++,user-controls,2d,player,maze
So I have my maze printed out once the user presses 1 in order to launch the map and other variables. I have declared the player as a smiley face or set equal to 1. However, I would like to make this character movable throughout the maze but am having...

Unity - Infinite sprite spawner stops spawning at a high speed

unity3d,2d,sprite
i wrote a script for my 2D car game for an infinite track. So i got a "killer" behind my car, that destroys all ground objects coming out the screen on the left and on the right i have a spawner that spawns all my blocky sprites in it and...

[ ][ ] and if-statement not working in code

java,arrays,if-statement,2d
I have some problems in the below code regarding the if-statement and possibly the 2D arrays, which I state below: int[][]image = { {0,0,2,0,0,0,0,0,0,0,0,2}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,5,5,5,5,5,5,5,5,0,0}, {0,0,5,5,5,5,5,5,5,5,0,0}, {0,0,5,5,5,5,5,5,5,5,0,0}, {2,0,5,5,5,5,5,5,5,5,0,2}, {0,0,5,5,5,5,5,5,5,5,0,0}, {0,0,5,5,5,5,5,5,5,5,0,0}, {0,0,5,5,5,5,5,5,5,5,0,0}, {0,0,5,5,5,5,5,5,5,5,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,2,0,0,0,0,0,0,0}//assume this rectangular image }; int[][]smooth = new...

IndexOutOfBoundsException: Index: 0, Size: 0 2D Arraylist

java,eclipse,arraylist,2d,dimension
I have this code ArrayList<ArrayList<Integer>> Pareto_set_List=new ArrayList<ArrayList<Integer>>(); for(Optimization_Problem.General_Calculation.Get_Another_Solution=0;Optimization_Problem.General_Calculation.Get_Another_Solution<Input.General_Inputs.Monte_Carlo_Step;Optimization_Problem.General_Calculation.Get_Another_Solution++){ int Count_Location=0;...

Unity 2d instantiating on mouse location trouble, Please advise

java,javascript,2d,unityscript
Ok i have looked all over the web for a solution to this, I may just be blind but if someone could help me out that would be great. The script I am writing is supposed to place a prefab where the mouse has clicked. this is supposed to happen...

Dynamicly resizeable custom Buttons - how to make?

unity3d,2d,photoshop,adobe-illustrator,unity3d-2dtools
please I have bought GUI pack for 2D mobile games. I have vectors for buttons but I don't know how to make it "smaller" - dynamically resizable for Unity. This is my bought button: And I need to make from it this (with all corners, etc.) In Unity, I will...

calling the method into matrix yields 0 instead of correct temps

java,matrix,methods,2d
Here's my new part of code: for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { double tempVal = inputFile.nextDouble(); degreeMatrix[i][j] = converter(tempVal); System.out.println(degreeMatrix[i][j]); ok so I created a file called, inMatrix.txt. Inside this file say i have a 4...

Make two physics objects not collide but do detect collisions in Unity

unity3d,2d,physics
I have a Unity project in which there is a 2D game world that consists of static colliders to make the geometry solid to the characters that inhabit it. The player is a dynamic collider (with a non-kinematic rigidbody). There's also an enemy character that is also a dynamic collider....

Calculate 2d coordinates in radius (for a tile based game)

java,2d
I've searched for a while and could not manage to find any satisfying answer. Currently I have a list of tiles (an int array representing the tile id), the width and height (in tiles). When I render it, all tiles are placed correctly, etc. But my real problem is that...

how to add Scoring to unity3D 2d top down car game?

unity3d,2d,car,topdown
I'm making 2D top down car game. as for now car game working with if player car hit enemy car game is over. I used for it adding tag to Enemy car and if player car collision detect enemy car with tag the finish the game. My question is: How...

Growing BorderPane based on child's Textnode content in JavaFX

3d,javafx,resize,2d,textnode
I have a problem figuering out what the best procedure would be, to have a growing and shrinking BorderPane. I want to try and enlarge or shrink the Pane horizontally, based on a Text node child it has (with changing text length). There are some additional constraints / problems that...

Unable to convert between 1d and 2d array values

java,arrays,matrix,2d
I realize this problem and solutions are all over StackOverflow like here however I'm still unable to make this work. Most of the examples say that I just need to multiply the row by the width and add the column meaning the location (4, 3) in a 4x4 square grid...

Unity 2D collisions - how to setup objects that collides among themselves

unity3d,2d,collision
I am starting with Unity 5 and I am straggling a bit with its 2D collisions. Looking a bit into it I found that there are three types of objects that can be defined: - Static: Just a 2D collider (2D collision box component for example). - Dynamic: 2D collider...

Surface plot piping to gnuplot from C

c,2d,gnuplot,surface,piping
I've made a function which successfully pipes data from my C program to gnuplot: void gnuprintabs(FILE *gp,double **RE,double **IM, double x[], int N) { int i,j; fprintf(gp, "splot '-'\n"); for (i=0; i<N; i++) { for(j=0; j<N; j++) { fprintf(gp, "%g %g %g\n", x[i],x[j],sqrt(RE[i][j]*RE[i][j]+IM[i][j]*IM[i][j])); } } fflush(gp); fprintf(gp, "e\n"); } The...

How can I correctly convert geographical coordinates to pixels on screen?

java,math,2d,map-projections,mercator
I'm trying to make a Java project that pinpoints the place on a image of a map, when given coordinates (taken from Google Maps). I've tried using the top-left corner of the image (place that has highest latitude, and the lowest longitude), as an some kind of an reference point,...

Android Rect set() method missing

java,android,graphics,2d,rect
I'm using Android Studio 1.1.0 and am trying to use the Rect .set() method in some code to set the edges of a newly-created rectangle, and I'm getting the message "Cannot resolve symbol 'set'" even though I imported android.graphics.Rect as prompted. When I declare a new Rect and define its...

Converting 2D screen coordinates to 3D Coordinates in PyQT

qt,3d,pyqt,2d,2d-3d-conversion
I am using PyQT for one of the first times, and I'm having trouble figuring out where a mouse click is in 3D space. Obviously it is not a perfect 1-to-1 mapping, but let's say that I click on a location (x, y, 0) on my QtGui. How can I...

Store txt file values into 2D array

c++,arrays,2d
Firstly, here is my code http://pastebin.com/BxpE7aFA. Now. I want to read a text file which looks like this http://pastebin.com/d3PWqSTV and put all those integers into an array, called level. level has a size of 100x25, which is declared at the top. My only problem now is where you see the...

Rendering multiple 2D images in OpenGL-ES 2.0

android,opengl-es,2d,opengl-es-2.0
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,...

Generating a random list of (x, y) points that satisfy a condition?

matlab,random,2d
So I need to generate a matrix of x and y points given that they meet the condition that at these (x,y) points concentration is greater than 10. Note that I first run a code that gives me concentration at each location, and now I need Matlab to "randomly" pick...

javascript 2D array from 2 1D array

javascript,arrays,2d
I would like to know if there is a builtin function of 2D array building from 2 1D arrays. Of course I can build such function my self but I wonder if there is already array manipulation library. Example: input: [1,3,5] and [2,4,6] => [[1,2], [3,4], [5,6]]...

Physics based 2D movement: Changing direction of an object over time

java,math,2d,physics,trigonometry
I am currently creating a 2D space game in Java, in which you control a ship in, well, space. The game does not use any external libraries. The ship is supposed to move towards the cursor. However, when moving the cursor, the old force does not magically disappear; the ship...

Blasting black circle in space invader

c++,algorithm,2d,marmalade
I'm trying to clone space invader, collision with the green barriers. https://www.youtube.com/watch?v=bLAhmnCZym4 Right now I have access to the pixels of the green barrier I would like to draw a solid black circle around the collision point of the bullet, right now I'm using the following code, but it spread...

Sorting 2D boxes into larger boxes to fill in the most efficient and complete manner

sorting,lua,2d,love2d
Background: Hello, so I've been working on this function for a bit and I'm stumbling. Ultimately, what I'm trying to accomplish is to have an application where a user inputs larger boxes, and also inputs a list of smaller boxes. (All 2 dimensional, by the way). The program then processes...

Ragged 2D int array pyramid with Java

java,arrays,for-loop,2d
Write the code required to allocate a ragged 2-D int array such that the first row has space to store 1 value, the second row can store 2 values, the third row has space to store 3 values, etc. up until the 50th row which has space to store 50...

JavaFX 2D text with background in 3D scene

java,3d,javafx,2d,javafx-3d
For my project, I need 2D text inside a 3D scene (not as overlay!). So I've tried adding a BorderPane with Label/Text nodes to my scene: The problem is however, that the white background of the panel is at times overlapping with the label (they have the same depth apparently)...

picture box crossed out C#

c#,graphics,2d,picturebox,gdi
I have a project in which I draw several rectangles using GDI. I do it using i++ from i=0 to i<=10. I use e.Graphics.FillRectangles. I refresh the drawn rectangles every 1/10s by calling Graphics.Invalidate() My problem is that my picture box gets crossed out when drawing more the 4 rectangles....

Plot 3d in 2d with numpy?

python,numpy,matplotlib,3d,2d
I am unable to plot 3D figures on my Linux computer using Numpy, because my graphics card does not have Linux support and the company's driver is basic. Is there away to write the data of the 3D plot directly into a 2D image, such as a 2D plot or...

Filling a polygon with maximum number of grid squares

algorithm,2d,polygon,rectangles
I've got a 2d polygon. I'm placing it on a square grid and marking the squares that are completely inside the shape. I need to find the placement that maximizes number of marked squares. The polygon orientation is fixed, it can be only translated. How can I do so?...

Why can't I make this array bigger?

c,arrays,2d
This code is working perfectly with an array size 200. Any bigger than that and it gives a runtime error. But why is it giving a runtime error? Is it because I don't have enough memory or something else ? This is the code: void matrix_multip(int matrix1[2500][2500],int matrix2[2500][2500],int n) {...

Reading from file and writing to 2D vector

c++,vector,2d,maze
When i tried to print my 2D vector, it's only read 3rd line (which is first line of maze) and ignore rest of maze. My maze is something like that; 11 11 X XXXXXXXXX X X 1 X X XXXXX X X X X X 1 XXXXX XXX X X...

Returning 2d array from void function in C

c,arrays,function,2d
I have a function that looks like this: void swapRows(int row_1, int row_2, double **matrix, int n, int m) { double arrTemp = (double *)malloc(m * sizeof(double)); int i; for(i = 0; i < m; i++) { arrTemp[i] = matrix[row_1][i]; *matrix[row_1][i] = matrix[row_2][i]; } for(i = 0; i < m;...