Is there any way to use a shader on just one spritebatch.draw call with XNA 4?
I want to use a shader just on the player but doing so would mean I loose the depth layering as I would have to end and begin the spritebatch more than once
[QUOTE=ZeekyHBomb;32439642]The actual formula would be
[cpp]SetNewtonBodyForce(body_id, (GetX() * cos(theta) - GetY() * -sin(theta)) * bPushForce, (GetX() * sin(theta) + GetY() * cos(theta)) * bPushForce, GetZ() * 0);[/cpp]
Since theta is 90°, cos(theta) is 0 and sin(theta) is 1, so
[cpp]SetNewtonBodyForce(body_id, -GetY() * bPushForce, GetX() * bPushForce, GetZ() * 0);[/cpp][/QUOTE]
Could you elaborate that a little further? Using your example code, I can push it left in 2 camera angles (0.32, 0 and -0.32, 0 I believe), but in the other two (0, 0.32 & 0, -0.32) it goes in a sort of diagonal, up-left-ish way.
It can't really go in a diagonal way, since x is 0, GetX() * bPushForce is 0, so it should only go in the y-direction.
The actual formula with the trigonometry is from the generic rotation matrix.
[editline]23rd September 2011[/editline]
Are you sure that stuff is normalized and you're using the right units (degrees / radians)?
[QUOTE=ZeekyHBomb;32440084]It can't really go in a diagonal way, since x is 0, GetX() * bPushForce is 0, so it should only go in the y-direction.
The actual formula with the trigonometry is from the generic rotation matrix.
[editline]23rd September 2011[/editline]
Are you sure that stuff is normalized and you're using the right units (degrees / radians)?[/QUOTE]
I'm not sure. This Camera System junk is messy as hell, I'm gonna try to write my own code to make the camera orbit the ball, then I'll get back to you.
[QUOTE=ROBO_DONUT;32428210]For printing?
You can't go wrong with LaTeX + Listings :v:[/QUOTE]
I exported from Notepad++ instead. Works like a charm. The only problem with Latex is that I'm too lazy to create a template.
Okay, I've programmed my own camera movement crap. Now I can use a simple variable to control the camera's orbiting around the ball, in degrees. However, before we move back to the topic of complicated physics I haven't been taught yet, I have a question.
How can I "smooth" the camera movement? As of now when the user presses "A", I just add 90 to the camera_dir variable. But how would I go about making a smooth transition from 0 to 90? Like, it starts off increasing slowly, the speeds up, and when it's about to get to 90, it slows down again.
[QUOTE=Samuka97;32440378]How can I "smooth" the camera movement? As of now when the user presses "A", I just add 90 to the camera_dir variable. But how would I go about making a smooth transition from 0 to 90? Like, it starts off increasing slowly, the speeds up, and when it's about to get to 90, it slows down again.[/QUOTE]
[QUOTE=Samuka97]
I'm working on a todo-list program, and I want to make it so when you tick a task, instead of it just popping away, I want it to fade out and then the tasks below it slowly move up. The question is, is there a formula you guys use for smooth movement? Like when you drag a slider, and instead of it just jumping to your mouse's position, it smoothly makes it way to it, accelerating and decelerating before it's end position.[/QUOTE]
[QUOTE=Dragonsdoom]Garry posted a thing on his blog about this. I think the topic you are referring to is interpolation.
[url]http://paulbourke.net/miscellaneous/interpolation/[/url]
Linear interpolation is the most common form, and is known as Lerp in some libraries.
I imagine if you have some kind of math utility library or class you may find pre-built methods there to handle different kinds of interpolation.[/quote]
Does this help?
On a different train of thought, I'm not sure that's the sort of camera you really want. If you are talking about user controlled cameras, Riemer did an XNA tutorial on 3d camera systems. He talked about creating a direction vector and multiplying it by a value based on the time elapsed in the game for a very smooth and precise movement: [URL="http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series4/Mouse_camera.php"]http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series4/Mouse_camera.php[/URL]
[QUOTE=Dragonsdoom;32440565]Does this help?
On a different train of thought, I'm not sure that's the sort of camera you really want. If you are talking about user controlled cameras, Riemer did an XNA tutorial on 3d camera systems. He talked about creating a direction vector and multiplying it by a value based on the time elapsed in the game for a very smooth and precise movement: [URL="http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series4/Mouse_camera.php"]http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series4/Mouse_camera.php[/URL][/QUOTE]
Oh, thanks! I didn't see your last post on my question. But what I'm looking for is Cosine interpolation, right? Because I want something [url=http://code.stephenmorley.org/javascript/smooth-movement/]much like this animation[/url].
Also, I don't understand much math and physics yet. I'm still in 7th grade (yeah, I'm young I know), so I probably need some help with this:
[cpp]double CosineInterpolate(
double y1,double y2,
double mu)
{
double mu2;
mu2 = (1-cos(mu*PI))/2;
return(y1*(1-mu2)+y2*mu2);
}[/cpp]
How would I go into implementing this into my camera rotation? I don't quite see what is the variable that indicates how much I want to "interpolate" in there, and the page doesn't really explain it either, unless I'm missing something very obvious.
[b]Edit:[/b] Thanks esalaka, I got it working.
mu is the multiplier
Essentially you call CosineInterpolate(position1, position2, speed)
Okay, back to the topic of applying a force to the ball to move it, I'm not sure how the camera system in Ogre3D works. I did a test just now to find out, but it didn't really tell me much. Anyways for each direction I faced, I called GetCameraDirection and wrote down the X and Y results (Z is useless because it's the height, and that's static). Here's what I got:
[quote=Note]
[b]DIR | X | Y[/b]
[b]U:[/b] 0.32 | 0
[b]D:[/b] -0.32 | 0
[b]R:[/b] 0 | 0.32
[b]L:[/b] 0 | -0.32[/quote]
I think that's why your formula wasn't working, and instead was making the ball go diagonal depending on which way the camera was facing. However, now that I rewrote the camera code, I can just base the formula around the camDir variable instead of the camera's ones, but I'm not sure how to do that.
I'm doing a program that is supposed to "decode" a string of text entered by the user.
Ex: Hello how are you doing
turns into
ouyed reaed owhed elloHed
I am having trouble setting this up. Our teacher gave us hints and said to use a for loop, strtok, and getchar() (I'm not really familiar with strtok or getchar). If someone can help me along that would be great.
Strtok?
You only need to create an array and loop through it backward while looping forward through the original string.
[QUOTE=esalaka;32441961]Strtok?
You only need to create an array and loop through it backward while looping forward through the original string.[/QUOTE]
That's what she said. I am reading up now on strtok and the function makes no sense for this assignment. It separates the sentences doesn't it?
Also, just want to make sure, I loop backwards while still going forward?
[QUOTE=esalaka;32441961]Strtok?
You only need to create an array and loop through it backward while looping forward through the original string.[/QUOTE]
strtok is the devil!
[QUOTE=RP.;32442302]strtok is the devil![/QUOTE]
Strtok that bad? Also to add ed to the end I just create a string and add it on there right?
[QUOTE=RP.;32442302]strtok is the devil![/QUOTE]
No it isn't. Stop being dramatic.
Yeah, it's a little backwards, but if you understand the quirks you can work around them.
TBQH, I'd go for BSD's strsep instead when it's available, but I know that's not always an option.
What I have so far:
[code]
#include <stdio.h>
int main()
{
char string[100];
int userString;
printf("Please enter a line of text. Enter new line to complete entry\n");
scanf("%s\n",userString);
printf("The encoded text is:\n%s\n", userString);
}
[/code]
Am I going in the right direction, or am I totally off? How would you set up the string into an array and then loop it?
[QUOTE=JooieKazooie;32442345]Strtok that bad? Also to add ed to the end I just create a string and add it on there right?[/QUOTE]
You have to know that strtok (and others like strsep) are destructive. They work by modifying the string you pass in. If you're not going to use the string elsewhere, then that's totally fine, otherwise you need to allocate a temporary buffer and copy the whole string over.
The other issue with strtok is that it's not re-entrant, meaning that if you run strtok on a string, you can't go and run it on another string then go back to the first one.
[editline]23rd September 2011[/editline]
[QUOTE=JooieKazooie;32442490]What I have so far:
[code]
#include <stdio.h>
int main()
{
char string[100];
int userString;
printf("Please enter a line of text. Enter new line to complete entry\n");
scanf("%s\n",userString);
printf("The encoded text is:\n%s\n", userString);
}
[/code]
Am I going in the right direction, or am I totally off? How would you set up the string into an array and then loop it?[/QUOTE]
Don't scanf strings without a character limit -- ever. That has a potential buffer overflow.
If your buffer is 100 characters long, do scanf("%99s\n", buffer); then manually set the last character to '\0'
Also, you have to be careful with allocating large arrays on the stack (100 chars is probably fine), but they probably haven't taught you any other method yet.
[QUOTE=ROBO_DONUT;32442461]No it isn't. Stop being dramatic.
Yeah, it's a little backwards, but if you understand the quirks you can work around them.
TBQH, I'd go for BSD's strsep instead when it's available, but I know that's not always an option.[/QUOTE]
I was kidding, I use it a lot when I need to parse simple things and I need something quick&easy to use.
It just that one time I spent around 3 hours trying to figure wtf was wrong with my code until I realized it was to do with strtok not being re-entrant (someone wrote about it like 2 post before this one).
Hello again, this time i'm back with another SFML question!
I'm trying to print a whole bunch of tiles to the screen, however i don't really want to loop through the array every frame so is there a better way of doing this? Heres what i have so far...
[code]
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <iostream>
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
// Clock object
sf::Clock Clock;
// Create main window
sf::RenderWindow App(sf::VideoMode(640, 640), "SFML RPG?");
App.UseVerticalSync(true);
for (int i = 0; i < 41; i++)
{
for(int k = 0; k < 41; k++)
{
int x = (i-1)*16;
int y = (k-1)*16;
App.Draw(sf::Shape::Rectangle( x, y, x+16, y+16, sf::Color::Red ) );
}
}
App.Display();
// Start game loop
while (App.IsOpened())
{
float Framerate = 1.f / Clock.GetElapsedTime();
Clock.Reset();
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
if (Event.Type == sf::Event::KeyPressed)
{
if(Event.Key.Code == sf::Key::A)
{
std::cout << Framerate << std::endl;
}
}
App.Draw(sf::Shape::Rectangle( 1, 1, 100, 100, sf::Color::Blue ) );
App.Display();
}
// Finally, display the rendered frame on screen
}
return EXIT_SUCCESS;
}
[/code]
Thanks!
[editline]24th September 2011[/editline]
Whoa what happened to my indenting
This is frustrating. I've been trying to draw something using non-deprecated OpenGL with OpenTK for ages now, but it just doesn't work. I've literally converted complete C++ tutorials on non-deprecated OpenGL to C#, but still, either nothing appears on the screen or I get some kind of access violation exception. Anyone who uses OpenTK willing to help me out?
generally AccessViolationException in OpenTK means that you're asking to render more vertices than you have laid out in memory. I'm assuming you're using GL.VertexAttribPointer and GL.DrawElements.
Here are the common mistakes that I've come across that can thrown an AccessViolationException:
VertexAttribPointer's first two numbers. The first one should be the location of the attribute (in for GLSL 1.30+), and the second number should be the number of values per attribute (eg 3 means that you'll load an array of {0, 1, 2, 3, 4, 5} into two vertex attributes - vec3(0, 1, 2) and vec3(3, 4, 5)).
GL.DrawElements requires the number of indices. Make sure that's stored somewhere else, and that you haven't done anything to it besides set it to indices.Length. Make sure the DrawElementsType is what you want it to be. Having your indices in bytes and telling OpenGL uints will make it think there are more allocated bytes than there really are.
None of these numbers are sizes in bytes. They are all numbers of attributes/indices. The only time you have to use size in bytes is with GL.BufferData<T>.
I always use the generic version of BufferData and BufferSubData...
GL.BufferData<float>(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * sizeof(float)), vertices, BufferUsageHint.StaticDraw);
So I've been working on this XNA game, and we're doing the maps so that the grounds are generated as polygons (see image). Right now we have a moving character and whatnot, alls good, but... we're using pixel-perfect collision detection. Which is great! But, obviously, slow. I've looked around a bit (even have a book for collision detection) but can't seem to get any heading on what "technique" I'm looking for. Primarily I wish to do AABB-Concave collision detection. I drew a beautiful box in the image to give you an idea of what a rectangular AABB shape looks like.
[img]http://dl.dropbox.com/u/11093974/Junk/aabbconcave.png[/img]
What technique do you guys recommend I use? (Any tutorials / books?)
edit: Maybe a BVH with triangles?
[QUOTE=jalb;32456303]So I've been working on this XNA game, and we're doing the maps so that the grounds are generated as polygons (see image). Right now we have a moving character and whatnot, alls good, but... we're using pixel-perfect collision detection. Which is great! But, obviously, slow. I've looked around a bit (even have a book for collision detection) but can't seem to get any heading on what "technique" I'm looking for. Primarily I wish to do AABB-Concave collision detection. I drew a beautiful box in the image to give you an idea of what a rectangular AABB shape looks like.
[img]http://dl.dropbox.com/u/11093974/Junk/aabbconcave.png[/img]
What technique do you guys recommend I use? (Any tutorials / books?)[/QUOTE]
It really depends on how many objects you plan to have. If you have only a few objects, then simply checking every AABB for a collision is perfectly fine. If you intend to have lots of objects, then that's probably not an option. I am using spherical bounding volume hierarchies to do frustum culling in 3D (and probably later help with collision detection), but the method should apply equally well to 2D AABBs. Basically what you do is you construct a tree where each node has bounding geometry which contains both of its children's bounding geometry (you want to place children in the tree so that nodes which are close in the tree are also close in space). Merging AABBs is as simple as taking the minimum of the minimum values of the AABBs and the maximum of the maximum AABB values. When trying to find AABB collisions, you go through the tree, skipping branches which don't collide and descending down branches with do until you find every potentially colliding leaf.
Once you've found all the potential collisions using the AABBs, you can run pixel-perfect collision on the overlapping region of the colliding AABBs.
Oh, I understand. However I'm trying to rule out pixel-perfect collision entirely if I can. If I can't I'll give that a shot.
I just realized that the way I'm doing it isn't [i]really[/i] concave. Well it sort of is, but sort of isn't. It's more of a bunch of convex polygons. Triangles, in fact.
[img]http://dl.dropbox.com/u/11093974/Junk/concavetriangles.png[/img]
I could just do triangle-aabb on each of these triangles. Maybe even use the separating axis theorem.
Is this a bad idea?
[QUOTE=jalb;32456949]Oh, I understand. However I'm trying to rule out pixel-perfect collision entirely if I can. If I can't I'll give that a shot.
I just realized that the way I'm doing it isn't [i]really[/i] concave. Well it sort of is, but sort of isn't. It's more of a bunch of convex polygons. Triangles, in fact.
[img]http://dl.dropbox.com/u/11093974/Junk/concavetriangles.png[/img]
I could just do triangle-aabb on each of these triangles. Maybe even use the separating axis theorem.
Is this a bad idea?[/QUOTE]
That's actually totally fine. It's the solution I would probably use, in fact.
Go for SAT. AABB is generally only used as a preliminary step unless your objects actually are axis-aligned boxes (which they usually aren't). You run a fast AABB test first, [i]then[/i] you run your more expensive test to verify potential collisions.
You don't have to triangulate that shape because it's already convex. If it's already convex, you can run the SAT test without any extra processing. If it's concave, then you need to break it up into convex chunks. This can be as simple as moving along the edges, finding interior corners, and subdividing along one of the edges that forms that corner. Either that, or just ignore concave stuff altogether and let the artist/whatever manually create bounding geometry made of purely convex shapes (which is what I would do).
C++ and OpenGL 1.1
Does anyone know what would be computationally cheapest way to not draw anything outside a certain rectangle?
E.g. I tell it to draw a line from x=1 to x=3, but my box is from x=0 to x=2, and so it draws only x=1 to x=2.
[QUOTE=Nikita;32463635]C++ and OpenGL 1.1
Does anyone know what would be computationally cheapest way to not draw anything outside a certain rectangle?
E.g. I tell it to draw a line from x=1 to x=3, but my box is from x=0 to x=2, and so it draws only x=1 to x=2.[/QUOTE]
View frustum/rect culling is exactly the same as a collision detection test. I use [url=http://en.wikipedia.org/wiki/Bounding_volume_hierarchy]bounding volume heirarchies[/url].
That being said, I think you've got the wrong idea about how it works. If you have a primitive that's halfway off-screen, OpenGL isn't going to draw any fragments that aren't visible. You pay for vertex transformations and fragment shading, and fragments are only drawn if they're visible and they pass the depth/stencil/alpha tests (if applicable).
Culling is used to bypass the [i]vertex transformation[/i] cost. It's a method of guessing whether or not the full primitive is going to be on-screen without doing the actual per-vertex transformations.
Or you could look into glEnable(GL_SCISSOR_TEST) and glScissor(x, y, w, h).
I may have misunderstood you, if you only want to draw within a certain area of your framebuffer, you can change the viewport with glViewport().
Sorry, you need to Log In to post a reply to this thread.