[QUOTE=Themage;33776984]I'm trying to make it so that when I press a mouse button it places the currently selected tile at that location and so far I have
[code]MouseState mouse = Mouse.GetState();
if (mouse.LeftButton == ButtonState.Pressed)
tileFilled = true;
TileX = (int)Math.Floor((float)(mouse.X / tileWidth));
TileY = (int)Math.Floor((float)(mouse.Y / tileHeight));
SquarePosition.X = (TileX * tileWidth)+(tileWidth/2);
SquarePosition.Y = (TileY * tileHeight) + (tileHeight / 2);
if (tileFilled == true)
spriteBatch.Draw at SquarePosition;[/code]
I don't know what I'm supposed to be doing at the bottom to make it actually draw my sprite.[/QUOTE]
Just pass in the texture and size and position based on what tile you selected to place.
[QUOTE=thrawn2787;33776093]Well I dunno if anyone can help but I'll ask anyways. I'm doing some 3D stuff in XNA (because OpenGL and DirectX are a bit above me). Anyways I have the camera bound to a 3D object a certain distance away. I want the camera to have all the same rotations as the object. Basically I have it all working except when it rotates on it's Z-axis, which is where I draw a blank.
So basically what I have to do is determine the camera's "up" vector in order to do this. So far I have:
[code]upVector.X = -1 * (float)(Math.Cos(boundObj.getRotationX() + (Math.PI / 2)) * Math.Sin(boundObj.getRotationY()));
upVector.Y = (float)(Math.Sin(boundObj.getRotationX() + (Math.PI / 2)));
upVector.Z = -1 * (float)(Math.Cos(boundObj.getRotationY()) * Math.Cos(boundObj.getRotationX() + (Math.PI / 2)));[/code]
Which works really well and all (it's actually what I used to find the objects "forward" vector just with 90 degrees more rotation in the Y). But I don't know how to incorporate the Z-Rotation. XNA can figure that out given the camera's up vector but again I'm not sure how to change it based off the Z rotation as well (as that code ^ only adjusts it based off the X and Y rotations, it should adjust if for all 3).
Picture because I'm probably bad at explaining it:
[img]http://dl.dropbox.com/u/11517902/rotations.png[/img][/QUOTE]
[csharp]
private void updateCamera()
{
Vector3 cameraPosition = new Vector3(0, 0.1f, 0.6f);
cameraPosition = Vector3.Transform(cameraPosition, Matrix.CreateFromQuaternion(shipRotation));
cameraPosition += shipPosition;
Vector3 cameraUp = new Vector3(0, 1, 0);
cameraUp = Vector3.Transform(cameraUp, Matrix.CreateFromQuaternion(shipRotation));
viewMatrix = Matrix.CreateLookAt(cameraPosition, shipPosition, cameraUp);
projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
device.Viewport.AspectRatio, 0.2f, 500.0f);
}
[/csharp]
Howdy everybody.
Got a tough one here.
Filter A:
[code]
object.ID < 300
[/code]
Filter B:
[code]
object.ID < 600
[/code]
Filter A is a 'subset' of Filter B, that is: Filter B will contain everything matched by Filter A, plus 0 or more objects.
On a Venn Diagram, Filter A would be inside Filter B.
Here's a more complicated example, demonstrating the potential complexity:
Filter A:
[code]
object.Col == 'GREEN' and (object.ID == 2 or object.ID == 64 or object.ID > 9001)
[/code]
Filter B:
[code]
(object.Col == 'RED' or object.Col == 'GREEN') and (object.ID == 3 or object.ID > 22)
[/code]
Filter A intersects Filter B, that is:
[code]
(Filter A) and (Filter B) = (object.Col == 'GREEN' and (object.ID == 64 or object.ID > 9001))
[/code]
On a Venn Diagram, Filter A and Filter B with intersect.
How can I obtain the equation of the intersection area (if any)?
If that's too difficult, then at least: how can I obtain a boolean on whether they intersect or not?
I'm working in Lua, but it's not really tied down to any specific language.
Help! Please :)
[editline]18th December 2011[/editline]
StackOverflow question: [url]http://stackoverflow.com/questions/8551002/operating-on-abstract-filters-list-comprehension-combining-two-filters[/url]
I am trying to learn c++, but stumbled on a problem. I made a console app where you fill in a slope value, x value and initial height, and let the computer calculate the height at the entered x. When this worked I tried to save the data to a .txt file, but it seems the program overrides the data when ran again.
My question is, how would I make the application so, that the program would run again, but add data instead of overriding it.
Thanks in advance.
[QUOTE=Chezburger;33781035]I am trying to learn c++, but stumbled on a problem. I made a console app where you fill in a slope value, x value and initial height, and let the computer calculate the height at the entered x. When this worked I tried to save the data to a .txt file, but it seems the program overrides the data when ran again.
My question is, how would I make the application so, that the program would run again, but add data instead of overriding it.
Thanks in advance.[/QUOTE]
I imagine your out-file definition looks something like this:
[cpp]
ofstream myFile("output.txt");
[/cpp]
You need to use the "append" write mode.
[cpp]
ofstream myFile;
myFile.open("output.txt", ios::app);
[/cpp]
[QUOTE=Chezburger;33781035]I am trying to learn c++, but stumbled on a problem. I made a console app where you fill in a slope value, x value and initial height, and let the computer calculate the height at the entered x. When this worked I tried to save the data to a .txt file, but it seems the program overrides the data when ran again.
My question is, how would I make the application so, that the program would run again, but add data instead of overriding it.
Thanks in advance.[/QUOTE]
You can set a stream's append flag.
[cpp]std::ofstream ofs("file.txt", std::ios::app);[/cpp]
e: Welp.
Thanks guys :) Will try this right away.
[b]edit:[/b]
works like a charm guys. Thanks again!
[QUOTE=Mr. Smartass;33777228][csharp]
private void updateCamera()
{
Vector3 cameraPosition = new Vector3(0, 0.1f, 0.6f);
cameraPosition = Vector3.Transform(cameraPosition, Matrix.CreateFromQuaternion(shipRotation));
cameraPosition += shipPosition;
Vector3 cameraUp = new Vector3(0, 1, 0);
cameraUp = Vector3.Transform(cameraUp, Matrix.CreateFromQuaternion(shipRotation));
viewMatrix = Matrix.CreateLookAt(cameraPosition, shipPosition, cameraUp);
projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
device.Viewport.AspectRatio, 0.2f, 500.0f);
}
[/csharp][/QUOTE]
Well see thing is maybe I'm doing all this shit wrong but it's the way I want to do it. I have the model rotate essentially on it's axises not the world's, so that doesn't quite work. I'd still have to figure out the models Up and Right vectors based off it's rotation (for when making the Quaternion).
Hello- I need some help with my Flash product, I'm currently working on implementing Google Maps into it and I've managed to get everything work with relative ease, apart from one thing. I would like to change the position of it (The X & Y axis) and I cannot figure out how? I've been looking through the [URL="http://code.google.com/apis/maps/documentation/flash/reference.html"]API documents[/URL] and cannot seem to figure it what I need to use to enable this? Any help would be much appreciated.
My current code is;
[CODE] import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapType;
import com.google.maps.controls.ZoomControl;
import com.google.maps.controls.PositionControl;
import com.google.maps.controls.MapTypeControl;
import com.google.maps.overlays.MarkerOptions;
import com.google.maps.overlays.Marker;
var map:Map = new Map();
map.key = "X";
map.setSize(new Point(480, 320));
map.sensor = "false";
map.addEventListener(MapEvent.MAP_READY, onMapReady);
this.addChild(map);
function onMapReady(event:MapEvent):void {
map.setCenter(new LatLng(XX, XX), 9, MapType.NORMAL_MAP_TYPE);
map.addControl(new ZoomControl());
map.addControl(new PositionControl());
map.addControl(new MapTypeControl());
var marker:Marker = new Marker(
new LatLng(XX, XX)
);
map.addOverlay(marker);
}[/CODE]
Here is what the current thing looks like;
[THUMB]http://i.imgur.com/qw63S.png[/THUMB]
I'm just guessing, but you could try getDisplayObject() and then modify the position of the DisplayObject.
Does this open successfully for you guys?
[url]http://pastebin.com/6dFs1Xim[/url]
It opens and closes for me. There doesn't seem to be anything wrong with loading images or initializing the screen from error checking. Rebuilding the project doesn't seem to help either.
vgasys.fon AKA System Bold is the greatest.
I wish XNA had .fon support.
Or that I didn't have to fuck around in Cygwin land to get a proper font extractor.
Woo, just got done learning about the argc and argv arugments within main(), and how to use atof/d/l/i to control them. Easy. Before that, I struggled through learning about functions that return a pointer that has pointer and array arguments. That shit is hard, man.
I'm working on something that'll quickly increase the speed of something when a key is held, then have it taper off. However, sometimes the movement stays at the decreasing value's speed, and not revert to 0. Anyone know what I'm doing wrong?
[csharp]
if (keys.IsKeyDown(Keys.D))
rollSpeed += 0.0005f;
if (keys.IsKeyDown(Keys.A))
rollSpeed -= 0.0005f;
if (keys.IsKeyUp(Keys.D) && keys.IsKeyUp(Keys.A))
{
if (rollSpeed < 0f)
rollSpeed += 0.0025f;
if (rollSpeed > 0f)
rollSpeed -= 0.0025f;
if ((rollSpeed == 0.0025f) || (rollSpeed == -0.0025f))
rollSpeed = 0;
}
[/csharp]
Floating Precision causes the if statement to never be hit.
Try changing it to:
[code]
if((rollSpeed >= 0.002 && rollSpeed <= 0.003) || (rollSpeed >= -0.003 && rollSpeed <= -0.002))
rollSpeed = 0;[/code]
[QUOTE=Lord Ned;33792112]Floating Precision causes the if statement to never be hit.
Try changing it to:
[code]
if((rollSpeed >= 0.002 && rollSpeed <= 0.003) || (rollSpeed >= -0.003 && rollSpeed <= -0.002))
rollSpeed = 0;[/code][/QUOTE]
The problem is persisting, but thanks a heap anyway.
[QUOTE=Mr. Smartass;33792666]The problem is persisting, but thanks a heap anyway.[/QUOTE]
Try printing out the value of rollSpeed before that check.
I'd actually have used
[code]if ( rollSpeed <= 0.0025f && rollSpeed >= -0.0025f ) //null speed when within 0.0025 of 0 either way
rollSpeed = 0;[/code]
[QUOTE=subenji99;33792760]I'd actually have used
[code]if ( rollSpeed <= 0.0025f && rollSpeed >= -0.0025f ) //null speed when within 0.0025 of 0 either way
rollSpeed = 0;[/code][/QUOTE]
This works like a charm, thanks!
[QUOTE=subenji99;33792760]I'd actually have used
[code]if ( rollSpeed <= 0.0025f && rollSpeed >= -0.0025f ) //null speed when within 0.0025 of 0 either way
rollSpeed = 0;[/code][/QUOTE]
Much better solution. Not sure why I didn't think of that. :v:
In XNA, my content folder suddenly corrupted, and now it isn't letting me make a new one. Tips?
[editline]19th December 2011[/editline]
New project's content folders are also corrupt.
[QUOTE=subenji99;33792760]I'd actually have used
[code]if ( rollSpeed <= 0.0025f && rollSpeed >= -0.0025f ) //null speed when within 0.0025 of 0 either way
rollSpeed = 0;[/code][/QUOTE]
[code]if ( -0.0025f <= rollSpeed && rollSpeed <= 0.0025f ) //null speed when within 0.0025 of 0 either way
rollSpeed = 0;[/code]
Is kind of a better way of writing it, that way you can visualize the values as if it were a number line.
It's a shame C++ doesn't support syntax like this:
[code]if ( -0.0025f <= rollSpeed <= 0.0025f ) rollSpeed = 0;[/code]
Is there any way to find out what version of DirectX a game uses in runtime? This is C#.
[QUOTE=thomasfn;33795528]It's a shame C++ doesn't support syntax like this:
[code]if ( -0.0025f <= rollSpeed <= 0.0025f ) rollSpeed = 0;[/code][/QUOTE]
Adding exceptions for things like that would be very odd. Comparisons result in boolean values.
[QUOTE=Jookia;33794146][code]if ( -0.0025f <= rollSpeed && rollSpeed <= 0.0025f ) //null speed when within 0.0025 of 0 either way
rollSpeed = 0;[/code]
Is kind of a better way of writing it, that way you can visualize the values as if it were a number line.[/QUOTE]
Write a function inrange that inrange(min, val, max) would do just that.
Well so I got a problem, I guess everyone has it sometimes. It's called creativity and it's a real b*tch.
I have no idea what to make, I recently learned pointers, arrays, classes, constructors, deconstructors and a little other things. But I have no idea what to do where I can impliment these syntaxes..
Any suggestions?
If you haven't figured it out it's c++ I am talking about.
[QUOTE=landizz;33800227]Well so I got a problem, I guess everyone has it sometimes. It's called creativity and it's a real b*tch.
I have no idea what to make, I recently learned pointers, arrays, classes, constructors, deconstructors and a little other things. But I have no idea what to do where I can impliment these syntaxes..
Any suggestions?
If you haven't figured it out it's c++ I am talking about.[/QUOTE]
I would recommend making a parser of some sort.
The first project I made in C++ was a config/ini file parser that parsed sections/keys into structured data that could be manipulated, then written back to the file. It got me familiar with classes and pointers. Depending on the data your parsing, you may use vectors, maps, arrays, linked lists and probably a lot of pointers.
But yeah, not sure how advanced you are yet, but I would recommend parsing some sort of data file.
[QUOTE=thisBrad;33800296]I would recommend making a parser of some sort.
The first project I made in C++ was a config/ini file parser that parsed sections/keys into structured data that could be manipulated, then written back to the file. It got me familiar with classes and pointers. Depending on the data your parsing, you may use vectors, maps, arrays, linked lists and probably a lot of pointers.
But yeah, not sure how advanced you are yet, but I would recommend parsing some sort of data file.[/QUOTE]
I'm not really advanced, yea I might know those syntaxes but I have never used them. The most advanced thing I have done probably would be my roulette game for the programming class or my text RPG (Which is like 2% done, barely done nothing on it).
A quiz in my C++ book had a question that had me write a program that needed a password parsed via commandline. I tried using an if statement like "if(argv[1] == "r"). That didn't work. So I tried doing pointers and shit with it, by making a pointer point to a string where the string was "r". I tried using strcmp, but I couldn't get that to work either. It turns out that the answer was so fucking obvious, it was just "if(!strcmp(argv[1] == "r")". That's the only thing I didn't try. Fuck, I overcomplicate things way too much.
Sorry, you need to Log In to post a reply to this thread.