C++ :: SDL Object Moves Too Fast
Jan 2, 2013
I am currently making pong using visual C++ with the SDL libary. I find that the ball moves too fast for the players and needs to slow down. The code for the movement is in a while loop and vairies speeds 1 - 2 (X and Y).
CODE:
//ball movement{
ballX += speedX;
ballY += speedY;
//}
ballX and ballY is the position of the ball.
speedX and speedY are the speeds. these change from 1 - 2
How to make the ball move less than one pixel or something along those lines.
View 8 Replies
ADVERTISEMENT
Nov 15, 2014
Ok so I have a function call that moves an Entity from one vector to another, and if one doesn't exist then it creates one and moves it:
std::vector<std::unique_ptr<Entity>> ActiveEntities;
std::vector<std::unique_ptr<Entity>> EntityPool;
// Creates a generic entity in the entity pool
void EntityManager::CreateEntity() {
[Code] .....
In this case it checks the entity pool for an entity, if one exists it moves it to the active entities and then returns the unique id, if one doesn't exist it creates one then calls itself to run the check again to verify and move the new entity.
My question is, is this a valid form of recursion since it only incurs a single loop of recursion, or should I reform the entire system to work differently? If so, how do you set this up in a way that does not cause recursion?
View 3 Replies
View Related
Sep 13, 2013
I'm writing a program that finds the probability of moves a Knight can make on a chess board. The program asks the user to enter the row and the column and the program is supposed to output how many possible moves the Knight can make, but the output is wrong. Example(if I enter row 1 and column 1 the output is 8 and it should be 2) I know the problem is with my if statements.
#include <iostream>
using namespace std;
int chess(int a, int b) {
int x =a;
int y = b;
int sum=0;
[code]....
View 3 Replies
View Related
Dec 7, 2014
i would like to make a planet that moves in a circle motion. I dont know how to start and how i can move a "planet" in a circle motion?
View 2 Replies
View Related
Feb 20, 2013
I just want to know how fast can C++ generate data? For example, I have a downstream device that is connected to my pc via a Gigabit Ethernet, and I have to generate some pattern and send it over the Gigabit interface.
I was curious if there is a way that I can see how fast I can generate data? I was curious if I can exercise a good portion of the bandwidth ! for example, sending about 600 Mbits/sec.
How do I find out, first, whether I can do this with C/C++, and, second, how do I know how fast I am sending data?
View 4 Replies
View Related
Dec 31, 2012
I want to build a server which holds hundreds of thousands of active users in memory. To keep all the users organized i would like to store them in a Vector.
The problem is how i could quickly and easy find the object whenever i need it? All users will have a unique ID. Would it be possible to keep some form of a Vector Index on the unique id number?
View 2 Replies
View Related
Feb 19, 2013
I have a question concerning the CDialogBar (:CControlBar).
I have a MDI application with a dockable toolbox (CDialogBar).
The user is able/allowed to move the DialogBar and to dock it at the right or left side When I dock at the left side, the content of my mdi-application (so all other open windows) are moved right (so the dockable bar moves the windows).
If i dock at the right side, nothing changes.
How can I change the behaviour of the bar, that the windows inside the application keep the same position when I dock left ?
(Problem is, that my windows are aligned on the right side of the application). When I dock the bar on the left, the windows are getting moved in the not visible area.)
View 2 Replies
View Related
Jun 9, 2013
i am looking for a verified code in simple c, for generating fft of an input image (.jpg). the output can be a text file including fft coefficients.can you recommend me any source except open-cv?
View 6 Replies
View Related
Apr 12, 2014
I'm attempting to build a column based database, and I'm new to C++ (just wanted to play around with building a column base database "for the fun of it"). I want to construct a very fast radix sort, that would allow me to quickly sort groups of columns based on integer values. My general preference is to take up more RAM to get more performance.
I'd like to build the radix sort by allowing 256 "buckets" to drop values in as I'm sorting. This allows me to sort through a group of 4 byte integers in only 4 passes. But assuming I'm trying to sort a large group of values (say 50+ million), I'm not sure what type of container to use for these. Also note I'm pretty unfamiliar with the "standard library", so below are my thoughts:
Vectors:
-Pros: Easy to use, and very fast for sequential and random access inserts / reads
-Cons: If they have to dynamically resize because a given vector wasn't large enough, this can apparently really slow performance. Unless I make another pass over the numbers before I start sorting, I wouldn't know how big to make individual the individual vectors. This means I either have to make them "too big" and waste space, or pay a performance price for either resizing, or scanning data first.
Lists:
-Pros: Seems like I wouldn't have to specify size ahead of time, so I could just easily insert values to a given list. Also, since I don't need random access reads (I'll ready the "0" list sequentially, then the "1" list, etc. they should work fine.
-Cons: I don't really know much about lists, but I'm not sure how easy it is to append a new value to the end of a list. I've read that standard library lists include both "forward" and "backward" pointers, which I don't need. Also, I find it hard to believe that there isn't some time taken up with memory allocation. If I build a list and append x million records in it, is it calling memory allocation routines x million times?
Or maybe there's another container type I should learn?
Again, my goal is to make this "fast", not "memory efficient". But having said that, the fastest way I could think of (use 256 vectors, each sized equal to the total number of members to be sorted) is just too much memory to burn - 256 times a vector big enough to hold millions of elements is too much.
View 4 Replies
View Related
Feb 10, 2012
I have a SSD and I am trying to use it to simulate my program I/O performance, however, IOPS calculated from my program is much much faster than IOMeter.
My SSD is PLEXTOR PX-128M3S, by IOMeter, its max 512B random read IOPS is around 94k (queue depth is 32). However my program (32 windows threads) can reach around 500k 512B IOPS, around 5 times of IOMeter!!! I did data validation but didn't find any error in data fetching. It's because my data fetching in order?
I paste my code belwo (it mainly fetch 512B from file and release it; I did use 4bytes (an int) to validate program logic and didn't find problem).
#include <stdio.h>
#include <Windows.h>
/*
** Purpose: Verify file random read IOPS in comparison with IOMeter
**/
//Global variables
long completeIOs = 0;
long completeBytes = 0;
int threadCount = 32;
unsigned long long length = 1073741824; //4G test file
[Code] ....
View 1 Replies
View Related
Mar 16, 2013
will copy constructor does object initialization using another already created object? I understand that it can be applied for object initialization and not for assignment.Is it correct?
View 10 Replies
View Related
Jul 3, 2014
I have a method to take a Tile object and make an instances of it based on some data from the original object. Than it is suppose to manipulate the a specific instance and save the results. The first loop through it works but it changes all instance as well as the base.
public static int recurse(int count, Tile[,] b,Huristic h,int check) {
if (check==1) {
boardState.Add(B)/>;
return check;
} if (check == 0)
[Code] .....
View 6 Replies
View Related
Dec 13, 2012
#include "B.h"
class A {
public :
A()
{
s_b = new B();
b = new B();
[Code] ....
In my project i have seen static object as above . But not able to know what is the exact use of it and how they are different from general object .
View 2 Replies
View Related
Sep 11, 2014
a function returns a temporary object like
int myfun(){
int x = 0;
return x;
}
this function will return a temporary integer now void fun1(const int & num); this function can receive from myfun().BUT void fun2(int & num); this function cannot receive from myfun() Why is that, Moreover what is lifetime of a temporary object like one returned in myfun() ???
View 7 Replies
View Related
Mar 28, 2014
I am trying to use web api in order to return custom json response keys. For this i have return a custom class to return json response
Custom Class:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
[Code].....
View 2 Replies
View Related
May 4, 2013
I have a combobox with Items 1024
2048
4096
8192
String cach = form.comboCache.SelectedItem.ToString();
I am using the above code to retrive an item selected by user,But this line is giving an exception "Null Reference Exception, Object reference not set to an instance of an object"
View 1 Replies
View Related
Mar 28, 2014
I am using session to pass object from controller to custom class in MVC Web API. here is my code, i am getting error at session.
public HttpResponseMessage Get()
{
var person = db.Persons.ToList();
[Code]....
View 1 Replies
View Related
Aug 23, 2013
In Visual Studio 2010 C++
I have a series of existing text objects
The text properties names are
item1_lbl,
item2_lbl,
item3_lbl,
….
Based on a selection I want to change an object. I generate the name of the object I want to change in a string so from this string is there a way to get a pointer to the correct text object that is same name?
View 3 Replies
View Related
Sep 22, 2014
I'm trying to figure out how I can create a vertex array object at offset of a vertex buffer object.I've created the buffer object. I'd like the "texs" idnex data to start at the texture coordinate content of the vertex_t structure.
Type definitions:
struct vertex_t {
vector3d_t position;
float s; // Texture coordinate s
float t; // Texture coordinate t
};
Code so far:
// How do I make this start at a certain spot of the VBO?!
glVertexAttribPointer(texs, 2, GL_FLOAT, GL_FALSE, sizeof(vector3d_t), nullptr;
//...
View 1 Replies
View Related
Jan 21, 2013
The case is like
class B{
public:
somedata;
somefunction();
}
class A{
public:
data;
function();
}
in somefunction i want a pointer to current object of class A m new to c++
View 2 Replies
View Related
Oct 31, 2013
I have an assignment that asks me to implement a variant of the classic bouncing balls program.
'Each ball should start off at the top of the screen with a random speed in the x direction. Whenever a ball hits a screen boundary it should bounce off at an angle equal to the impact angle and lose some speed. Eventually each ball should come to a rest at the bottom of the screen. Five seconds after coming to a rest a ball should be removed from the screen.'
'Your code must keep track of objects (balls) by placing the object data structures in a linked list. You need to create your own linked list implementation. Below is a brief description of the object programming interface: CreateObject - Create a new object. The function accepts as input parameters a pointer to the SDL screen, a pointer to a model triangle array, and a variable telling the size of the model triangle array. The function returns a pointer to a new object data structure. The model triangle array specified as input parameter should not be shared across objects. (Not sharing the model triangle array allows e.g. objects to have different colors.)
Perform the necessary memory allocation and copying.DestroyObject - Free object. The function accepts as input parameters a pointer to an object data structure. The function should free all memory allocated to represent the object (memory allocated for the model triangle array and the object data structure itself).
Drawobject - Draw object on screen. The function accepts as input parameters a pointer to an object data structure. The function must draw the object on the screen by calling DrawTriangle on each of the model triangles. Remember to update scale, translation, etc., in each triangle data structure before invoking DrawTriangle.
Hint: Do not make the bouncing algorithm too complex. Bouncing a ball off a vertical or horizontal surface can be accomplished without resorting to calculating impact angles.'
The function I'm stuck at, is the first one - createobject.
My first aim is to get one ball on the screen.
Code:
// Create new object
object_t *CreateObject(SDL_Surface *screen, triangle_t *model, int numtriangles)
{
object_t *object = malloc(sizeof(object_t));
object->model = malloc(sizeof(sphere_model));
object->screen = SDL_Surface;
memcpy(*model, object->model, sizeof(object_t));
return object;
// Implement me
}
This is what I've done so far.
View 4 Replies
View Related
Dec 21, 2013
I have two classes one called Date and the other is University , Date class has two overloaded operators , ostream and istream to take in the data and print them out :
ostream & operator<<(ostream & out, Date & x) {
out<< x.month << "/" << x.day << "/" << x.year ;
return out;
[Code] ....
The University class has an object of type Date called establishDate and I must use this to print out the date along with the University name and location, here's University class :
University.h
class University {
public:
University (); // constructor
friend ostream & operator<<(ostream & out, University & x); // print the university data
friend istream & operator>>(istream & in, University & x); // to read university data
[Code] .....
so how do I use the establishDate object ?
View 2 Replies
View Related
Apr 20, 2013
it is not possible to get a type from an object, only from a type. Even with auto, you can only instantiate another type of the same type.I'd like to get a type from an object given another type, mainly because it is less typing and less error prone.
Some psudocode:
Type1 A<X, Y> a;
int b;
Type2 a.InnerType<b>::type c; // obviously won't work
A work around I thought of would be to use functions:
Type1 A<X, Y> a;
int b;
auto c = a.getInnerType(b);
Which is kinda interesting and looks like the way I'm going to go. However, I'm just wondering if there is any other ways of doing this as I don't really want to instantiate an object if I can avoid it (though the optimizer will probably just dump it anyway).
View 2 Replies
View Related
Jun 27, 2013
I have the following problem, I have an object of a class Subject, and I want that this object points to another object of class Classes, creating a kind of link. How can I do that?
View 4 Replies
View Related
May 26, 2014
So I am trying to develop a sort of 2d spacesim engine for creating games in C++. The project uses SFML for graphics, and I am currently trying to compile it on Linux using g++.
The main issue that I am wrestling with is that of simulation objects having their position, velocity, and rotation variables constantly getting set to NaN for reasons that are beyond me. The behaviour is not consistent, and occasionally will occur or not occur without any discernible pattern.
The github repo for the code is here: [URL] ....
I understand that NaN values can spread easily by operations on one another, but I cant seem to figure out where the initial issue is occurring here.
View 2 Replies
View Related
Mar 11, 2013
is it possible to get object name in the constructor? I would like to initialize an object of circle class without any arguments and put some pretty lines in constructor to get and save as table of chars the name of creating object. Is it possible? I work with MSVS2012.
View 4 Replies
View Related