If you use C++11 you can use [url=http://en.cppreference.com/w/cpp/chrono/high_resolution_clock]std::chrono::high_resolution_clock[/url], or perhaps
[cpp]typedef std::conditional<std::chrono::high_resolution_clock::is_steady(), std::chrono::high_resolution_clock, std::chrono::steady_clock> clock;[/cpp]
Which chooses [url=http://en.cppreference.com/w/cpp/chrono/steady_clock]std::chrono::steady_clock[/url] if the high resolution clock is not steady.
So much std in there
[editline]27th November 2011[/editline]
Also, is std::conditional a part of C++11 as well?
[QUOTE=ROBO_DONUT;33450677]You're using two different conventions for 'yaw' in the calculations for 'direction' and 'right'.
For 'direction', the x-component is proportional to sin(yaw), while the z-component is proportional to cos(yaw). You do the exact opposite for 'right': x = cos(yaw - pi/2), z = sin(yaw - pi/2)
You could drop the pi/2 altogether and make right.x = -cos(yaw) and right.z = sin(yaw), or you could leave the pi/2 in there and adopt the convention you use for 'direction' (right.x = sin(yaw-pi/2), right.z = cos(yaw-pi/2))
It really helps to draw these things, if you're having trouble visualizing it.[/QUOTE]
All right, thanks a lot. I'll try this when I get home. Thanks again.
To try and stop doing basic shit I'm stepping the challenge up a notch with a text editor. I'm having problem with this block of code in my actionPerformed method.
[CODE]else if (e.getSource() == open) {
JFileChooser choice = new JFileChooser();
int option = choice.showOpenDialog(this);
if (option == JFileChooser.APPROVE_OPTION) {
try{
Scanner scan = new Scanner(new FileReader((open).getSelectedFile().getPath()));
}
}[/CODE]
Specifically the try block. Eclipse is telling me that getSelectedFile() is undefined for JMenuItem. I know I could simply use a MenuItem and it would work, but then I would have to switch the rest of the Swing components to AWT, which I don't want as I want the program to be primarily Swing oriented. Is there another way I could open a file with Swing?
EDIT: Just double checked and it looks like it's undefined for MenuItem too. What can I do to get the Scanner to be "on" the file?
Does anyone know where I can get sounds for a piano I'm making? All I can find are piano synthesizers and crappy music videos.
[QUOTE=Themage;33455897]Does anyone know where I can get sounds for a piano I'm making? All I can find are piano synthesizers and crappy music videos.[/QUOTE]
Download the trial of FL Studio and export them from there.
I'm programming Java using Netbeans. I'm using Matisse to create the GUI.
The assignment is to create a basic calendar, including comboboxes for the month and year. I have a string array of the month names (January, February...) and want to use those values as the values in the combobox. However, I can't figure out how to put the values from the array into the combobox. Any ideas?
Loop through the array and make each element of the array a selection in the combobox.
[QUOTE=Octave;33456915]Loop through the array and make each element of the array a selection in the combobox.[/QUOTE]
For the loop, how do I find the length of the array? This isn't working, it returns "illegal start of expression"
[code]javax.swing.JComboBox jMonth = for(int i = 0; i < monthNames.length; i++)
jMonth.addItem(monthNames[i]);[/code]
[editline]26th November 2011[/editline]
jMonth is the combo box, monthNames is the array of strings.
[QUOTE=Corndog Ninja;33456996]For the loop, how do I find the length of the array? This isn't working, it returns "illegal start of expression"
[code]javax.swing.JComboBox jMonth = for(int i = 0; i < monthNames.length; i++)
jMonth.addItem(monthNames[i]);[/code]
[editline]26th November 2011[/editline]
jMonth is the combo box, monthNames is the array of strings.[/QUOTE]
It's monthNames.length(), i think length is a method.
Also, I'm not a java programmer but it seems fishy that you can assign a variable to a for loop. Try:
[code]javax.swing.JComboBox jMonth;
for (int i = 0; i < monthNames.length(); i++)
jMonth.addItem(monthNames[i]);[/code]
[QUOTE=Octave;33457033]It's monthNames.length(), i think length is a method.
Also, I'm not a java programmer but it seems fishy that you can assign a variable to a for loop. Try:
[code]javax.swing.JComboBox jMonth;
for (int i = 0; i < monthNames.length(); i++)
jMonth.addItem(monthNames[i]);[/code][/QUOTE]
Looks like I had that code assigned to custom creation, rather than post-creation. Thanks for that!
[sub]also length isn't a method[/sub]
[code]javax.swing.JComboBox jMonth;
for (int i = 0; i < monthNames.length; i++)
jMonth.addItem(monthNames[i]);[/code]
[editline]26th November 2011[/editline]
[B]That fixed the errors, but it's still not running right.[/B]
Here's the code:
[IMG]http://i.imgur.com/AjScc.png[/IMG]
And here's the GUI:
[IMG]http://i.imgur.com/gmzTq.png[/IMG]
[QUOTE=esalaka;33453341]So much std in there
[editline]27th November 2011[/editline]
Also, is std::conditional a part of C++11 as well?[/QUOTE]
Yes, §20.9.7.6
[quote=n3242]template <bool B, class T, class F> struct conditional;
If B is true, the member typedef type shall equal T. If B is false, the member typedef type shall equal F.[/quote]
Anyone here any good with mysql?
I have a task set whereby I need o calculate peoples age in a query using only their DoB, but were not using any proglamming language just pure sql commands and I have no idea how it would be done
Does anybody know a good book on making games in objective-c (iOS games, for example), I understand objective-c. I just need a book on making games with it, as that is my main interest.
-Snip- Nevermind..
Anyone have experience with taking a Native DirectX window and running it inside a managed C# WinForm?
I can find lots of posts/code examples on the internet, but none of the downloadable code actually works. :/
Under code::blocks, is there any predefinition like _DEBUG when you're running your program under debug? There is in visual c++ right?
[QUOTE=likesoursugar;33476069]Under code::blocks, is there any predefinition like _DEBUG when you're running your program under debug? There is in visual c++ right?[/QUOTE]
Learn about Makefiles and do it yourself.
[QUOTE=Soviet_Banter;33476120]Learn about Makefiles and do it yourself.[/QUOTE]
Found it, or Project->Build options...->Debug->#defines
Hi guys, I'm trying to draw a map using XNA. What I do is store my map data in a file (Map1.map) with the layout:
tileId;Collide?;(X,Y);Angle;Width;Height
Here's my map:
[quote]0;true;(100,300);0;50;50
0;true;(100,100);0;50;50[/quote]
It only draws the top row for some reason, but it's getting the data for both.
Here's my MapReader code:
[cpp]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace The_Game_With_No_Name
{
public struct MapProperties
{
public int tileId;
public bool doCollide;
//public Vector2 Position;
public int X;
public int Y;
public float Angle;
public int Width;
public int Height;
}
public struct PropProperties
{
public string propId;
public bool doCollide;
public Vector2 Position;
public float Angle;
}
public class MapReader
{
MapProperties[] MapProperties;
PropProperties[] PropProperties;
private string _contentFolder;
private string _Map;
public void Read(string contentFolder, string Map)
{
_contentFolder = contentFolder;
_Map = Map;
using(StreamReader S = new StreamReader(_contentFolder + @"\Maps\" + _Map + @"\" + _Map + ".map"))
{
//Read map with tiles
string[] M = S.ReadToEnd().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
MapProperties = new MapProperties[M.Length];
for (int x = 0; x < M.Length; x++)
{
foreach (string M1 in M)
{
string[] D = M1.Split(';');
MapProperties[x].tileId = Convert.ToInt32(D[0]);
MapProperties[x].doCollide = Convert.ToBoolean(D[1]);
MapProperties[x].X = Convert.ToInt32(D[2].Split(',')[0].Split('(')[1]);
MapProperties[x].Y = Convert.ToInt32(D[2].Split(',')[1].Split(')')[0]);
MapProperties[x].Angle = Convert.ToInt32(D[3]);
MapProperties[x].Width = Convert.ToInt32(D[4]);
MapProperties[x].Height = Convert.ToInt32(D[5]);
}
}
}
//using (StreamReader S = new StreamReader(_contentFolder + @"\Maps" + _Map + @"\" + _Map + ".prop"))
//{
// //Read map with props and other stuff
// string[] M = S.ReadToEnd().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
// PropProperties = new PropProperties[M.Length];
// for (int x = 0; x < M.Length; x++)
// {
// foreach (string M1 in M)
// {
// string[] D = M1.Split(';');
// PropProperties[x].propId = D[0].ToString();
// PropProperties[x].doCollide = Convert.ToBoolean(D[1]);
// PropProperties[x].Position = new Vector2(Convert.ToInt32(D[2].Split(',')[0].Split('(')[1]), Convert.ToInt32(D[2].Split(',')[1].Split(')')[0]));
// PropProperties[x].Angle = Convert.ToInt32(D[3]);
// }
// }
//}
}
public void Draw(SpriteBatch SpriteBatch, Texture2D[] tileTextures, SpriteFont font)
{
foreach (MapProperties MapProperty in MapProperties)
{
SpriteBatch.Draw(tileTextures[MapProperty.tileId], new Rectangle(MapProperty.X, MapProperty.Y, 50, 50), Color.White);
}
}
}
}[/cpp]
[editline]28th November 2011[/editline]
And it only shows this:
[url]http://speedcap.net/img/aadeb96bb708a2e5bceb75a7a95c8002/af5fe65c.png[/url]
*snip* wrong thread
Does anyone know if there is a way around the [url=http://msdn.microsoft.com/en-us/library/windows/desktop/ms740548%28v=vs.85%29.aspx]raw socket restrictions[/url] on windows? Can winpcap send packets to a network interface getting around it?
[IMG]http://i1095.photobucket.com/albums/i474/Jordan_Oyenusi/help2.png[/IMG]
What does this error mean ? How do I solve it ?
[QUOTE=joyenusi;33477942]What does this error mean ? How do I solve it ?[IMG]http://i1095.photobucket.com/albums/i474/Jordan_Oyenusi/help2.png[/IMG][/QUOTE]
You're modifying (in this case, removing) an item in the collection. It makes the foreach corrupt.
If I were you, I would use a regular for loop:
[code]
for(int i = 0; i < particles.Count(); i++)
{
if(particles[i].ttl <= 0)
{
particles.RemoveAt(i);
i--; //since we removed an item, we move back the for loop so we don't skip the next item
}
}
[/code]
Okay.
When I change my code from, this.
[CODE]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace ParticalCollisionsVer2
{
class Particle
{
public Vector2 pos;
public Texture2D texture;
public Vector2 velocity;
public int gravity;
public int ttl;
public Particle(Texture2D Texture, Vector2 Pos)
{
texture = Texture;
pos = Pos;
velocity = new Vector2(0, 0);
gravity = 1;
}
public void Update()
{
if (pos.Y + texture.Height >= 400)
pos.Y = 400 - texture.Height;
velocity = -(velocity);
velocity.Y += gravity;
pos += velocity;
ttl -= 1;
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, pos, Color.White);
}
}
}
[/CODE]
to this:
[CODE]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace ParticalCollisionsVer2
{
class Particle
{
public Vector2 pos;
public Texture2D texture;
public Vector2 velocity;
public int gravity;
public int ttl;
Color color;
public Particle(Texture2D Texture, Vector2 Pos)
{
texture = Texture;
pos = Pos;
velocity = new Vector2(0, 0);
gravity = 1;
color = Color.White;
}
public void Update()
{
if (pos.Y + texture.Height >= 400)
color = Color.Red;
pos.Y = 400 - texture.Height;
velocity = -(velocity);
velocity.Y += gravity;
pos += velocity;
ttl -= 1;
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, pos, color);
}
}
}
[/CODE]
My mouse can only move along the X axis... WTF is going on ?
EDIT: in fact it's just when I add [CODE]color = Color.Red;[/CODE]
[QUOTE=joyenusi;33478341]Okay.
When I change my code from, this.
My mouse can only move along the X axis... WTF is going on ?[/QUOTE]
You are missing braces.
[csharp]
if (pos.Y + texture.Height >= 400)
color = Color.Red;
pos.Y = 400 - texture.Height;
velocity = -(velocity);[/csharp]
[csharp]
if (pos.Y + texture.Height >= 400)
{
color = Color.Red;
pos.Y = 400 - texture.Height;
velocity = -(velocity);
}[/csharp]
Thanks, I appreciate you putting up with my mistakes.
I'm in an intro to java class, and while I understand what to do, the syntax of it all is confusing me.
There are two parts ([URL]http://209.189.201.185/mpanitz/Courses/2011Fa/BIT115/Homeworks/A4_Easier/AssignmentDescription.html[/URL])
The first part is using a robot we use in our class. [URL]http://209.189.201.185/mpanitz/Courses/2011Fa/BIT115/Software/becker.jar[/URL] This is the .jar file for the robot.
The second part is to print out the same histogram as stars in the Java I/O. Whats really confusing me is how to reference everything in the code, because it's stored in an array.
Here's what I have:
[code]
import becker.robots.*;
class HistogramRobot extends Robot
{
HistogramRobot(City c, int st, int ave, Direction dir, int num)
{
super(c, st, ave, dir, num);
}
public void drawRow( int width )
{
}
public void turnRight()
{
this.turnAround();
this.turnLeft();
}
public void turnAround()
{
this.turnLeft();
this.turnLeft();
}
}
class HistogramPrinter extends Object
{
public void printHistogram( )
{
int counter;
for(counter=0;counter<histogramData.length;counter++)
{
int i =0;
for(i = 0; i < histogramData[counter]; i++)
{
System.out.print("*");
}
System.out.println(" ");
// numStars = keyboard.nextInt();
// int counter = 0;
// while( counter < numStars)
// {
// System.out.print("*");
// counter++;
}
}
}
}
public class DrawHistogram extends Object
{
public static void main(String[] args)
{
City c = new City(12, 12);
HistogramRobot drawingBot = new HistogramRobot(c, 1, 1, Direction.EAST, 1000);
HistogramPrinter histPrinter = new HistogramPrinter();
int [] histogramData = new int[7];
histogramData[0] = 3;
histogramData[1] = 5;
histogramData[2] = 1;
histogramData[3] = 0;
histogramData[4] = 4;
histogramData[5] = 2;
histogramData[6] = 1;
// Make the robot 'draw' the (horizontal) histogram of Things here
for(int i=0;i<histogramData.length;i++)
{
drawingBot.drawRow(i);
}
// Call printHistogram here:
histPrinter.printHistogram();
}
}
[/code]
I'm working on an Achievement system for Android and I'm just looking for a simple way to store all the achievements and your progress for each. I need to store: id, title, description, points, current value, max value, and an image path for EACH achievement.
I tried using the SQLite services and everything but I can't seem to get that working that well, so I just want to use some basic text tables for now. I know you use the FileBuffer and I know how to write to text files, I'm just not sure the best approach to format them and how to read them in.
I was thinking of formatting the table something like this:
[code]
{
{
id = 0,
Title = "Sample Achievement",
Desc = "Sample description",
Points = 5,
CurVal = 3,
MaxVal = 10,
Img = "path/to/img.jpg",
}
{
id = 1;
...
[/code]
That would give me access to each achievement as its own subtable, or something like that and I can build an Achievement object around the values I get back for later use.
Open to different methods/ideas.
[QUOTE=Feihc;33482687]I'm working on an Achievement system for Android and I'm just looking for a simple way to store all the achievements and your progress for each. I need to store: id, title, description, points, current value, max value, and an image path for EACH achievement.
I tried using the SQLite services and everything but I can't seem to get that working that well, so I just want to use some basic text tables for now. I know you use the FileBuffer and I know how to write to text files, I'm just not sure the best approach to format them and how to read them in.
I was thinking of formatting the table something like this:
[code]
{
{
id = 0,
Title = "Sample Achievement",
Desc = "Sample description",
Points = 5,
CurVal = 3,
MaxVal = 10,
Img = "path/to/img.jpg",
}
{
id = 1;
...
[/code]
That would give me access to each achievement as its own subtable, or something like that and I can build an Achievement object around the values I get back for later use.
Open to different methods/ideas.[/QUOTE]
Is that JSON? If not,use Google/Android's JSON library.
Sorry, you need to Log In to post a reply to this thread.