C++ :: Checking For 3D Primitive Collisions

Aug 4, 2013

I think I may have found a new way of checking for 3d polygon collisions, but I'm not sure. The method involves...

1. finding the planes that the primitives lie on
2. finding the line where the planes intersect
3. if both polys have points on both sides of the line AND have points that overlap on the 1d space of the line, then they intersect.

I have some half done code testing this, and so far it seems to be sound and fairly fast. These are some average time-tests done on my machine for each part:

1. 30 microseconds (both)
2. 7 microseconds
3. TBD

View 5 Replies


ADVERTISEMENT

C++ :: Tile Replacement And Collisions In SDL

Mar 26, 2014

how to replace tiles within a map. My map data is in a .map file and I'm wondering how I can manipulate it to change the tiles.For example, If i kill an enemy, I would want his sprite to go away. I need to know how to do this. I also need to know how to have collisions work. At the moment I have a system where it checks if the tile in a certain direction (based on whatever arrow-key I press) is a certain tile by using its variable name TILE_TILENAME. I'm likely not doing this right, as collisions do not work, but the game still runs fine.

Here is some of my code;

//The tile
class Tile
{
private:
//The attributes of the tile

[Code]....

View 1 Replies View Related

C++ :: Using New On Primitive Data Types

Dec 12, 2014

int* count;
count = new int(1); // what???

Is this on the heap?? do i have to delete it now?

So is 'new' on a primitive data type just a way for me to allocate primitive data types (int, char, etc.) on the heap instead of the stack?

And, out of curiosity, can you do that in Java?

View 4 Replies View Related

C++ :: Conversions Between Integer Primitive Data Types

May 8, 2014

In my platform (Windows 7 Ultimate 64 bits with Service Pack 1 over a compatible PC with a AMD x86 microprocessor), the next sample C++ code,

#include <iostream>
#include <limits>
using std::cout;
using std::endl;
using std::hex;
using std::showbase;
using std::numeric_limits;

[Code] ....

Compiled with Microsoft Visual C++ 2010 Express, prints this output:

ui = 0xffffffff
ull = 0xffffffff
sll = 0xffffffff
si = 0xffffffff
ull = 0xffffffffffffffff
sll = 0xffffffffffffffff

So, in my platform, conversion from an unsigend integer primitive data type to any bigger integer primitive data type never extends the most significant bit of the former integer and conversion from an signed integer primitive data type to any bigger integer primitive data type always extends the most significant bit of the former integer. This is convenient to mantain the same value when converting between integer primitive data types of the same signedness (i.e, signed integers or unsigned integers).

View 4 Replies View Related

C++ :: Initializing Generic Type That Can Be Both Primitive And Object?

Apr 1, 2013

I have defined my own class, Queue, which inherits from my own class, LinkedList. I have been using templates to allow Queues to be of int, string, etc types.

But now I want to be able to store objects in my Queue type. And so the problem I have is that in my LinkedList class, I have two instances where I initialize an instance of my generic type T to 0.

For instance, the removeFirst() method starts like this:

template <typename T>
T LinkedList<T>::removeFirst() {
T a = 0;

And so the compiler complains that it can't convert from int to [in this case] Command&.

What to do?

View 2 Replies View Related

C++ :: When Are Rvalue References To Primitive Integers Short-lived Or Long-lived

Sep 4, 2012

I have done some experimentation on rvalue references with the TDM-GCC 4.6.1 compiler and made some interesting observations that I cannot explain away with theories. I have a very simple program that does not deal with objects but int primitives and that has defined 2 functions:

foo1 (returning a local variable by rvalue reference) and
foo2 (returning a local variable by value)

#include <iostream>
using namespace std;
int &&foo1();
int foo2();
int main() {
int&& variable1 = foo1();

[Code] .....

It seems the value returned by foo1 and received by variable1 dies out after some time - perhaps, a brief period of some milliseconds. Notice that I have prevented cout from printing "My name is softwarelover" by commenting it out. If I allow that statement to run, the result is different. Instead of printing 5, 0 it prints 0, 0. Seems like it is because of the time-delay introduced by "cout << "My name is softwarelover." that 5 turns into 0.

Is the above how an rvalue reference is supposed to behave when referring to a primitive integer which a function returned by reference as opposed to return-by-value? By the way, why is it 0, why not garbage?

Notice also that variable2 never seems to die out, no matter how many times I print it with cout! variable2 refers to a primitive integer which a function returned by value, not return-by-reference.

View 8 Replies View Related

C :: Bit Checking - Stack Overflow

Sep 19, 2013

I usually check if a bit is set using:

Code: bit = (number >> n) & 1; where `n` is the bit I want to check...

But I came across a stackoverflow answer saying:

bit = number & (1 << x); will not put the value of bit x into bit unless bit has type _Bool (<stdbool.h>).

Otherwise, bit = !!(number & (1 << x)); will..

So why is this? why the double !?

View 5 Replies View Related

C :: Checking Whether A String Is Palindrome Or Not

Nov 4, 2013

Everything seems to be correct from my perspective. heres the program: Code: /*c program to check whether a string is palindrome or not*/

#include<stdio.h>
#include<string.h>

int main(void) {
char str[30];
int i,j,flag=0;

[Code] .....

View 1 Replies View Related

C :: How To Turn Up Error Checking On IDE

Dec 8, 2013

The reason being is that it says that my program is right

Code:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define NFlights 10
struct date {
int month;
int day;
int year;
int hour;
int minute;

[Code] ....

View 6 Replies View Related

C :: Language Syntax Checking

Jun 15, 2013

Q. In context of C language syntax checking, which of the following can be modeled using Finite Automata?

(A) Detecting proper termination of an instruction.
(B) Detecting balance of parentheses.
(C) Detecting initialization of a variable.
(D) None of the above.

View 4 Replies View Related

C++ :: Checking If Key With Modifier Pressed?

Jan 31, 2015

I am new to C++ , i want to know how to check if a key with modifier is pressed.

When I use GetAsyncKeyState() it gives me error identifier not found.

View 1 Replies View Related

C++ :: Checking If A Program Is Running?

Jun 17, 2014

I have a question, how can I check if a program is running using c++? For example

if (notepad.exe is running) {
.... ..... ....

View 3 Replies View Related

C++ :: Checking For Deallocated Memory?

Jul 20, 2014

How would I go about checking for deallocated memory?

For example, let's take this into consideration:

// Unsigned 32-bit / 64-bit integer: uint32, uint64
uint32* Pointer = new uint32[ Size ];
uint64 MemAddr = ( uint64 ) Pointer;
delete[] Pointer;

The above code would proceed to create a new array, store it in a pointer and retrieve the memory address of the array before finally deleting the array.

So let's assume we re-build the pointer and try to access the now deallocated array:

Pointer = ( uint32* ) MemAddr;
Pointer[ 0 ] = 0;

Based on the above snippets of code, how would I check "Pointer" after rebuilding the memory to check if the rebuilt memory has actually been deallocated. Without a check we'd get an exception error.

A bit of detail on why I am trying this:

Before thinking up how to do this, I was storing the addresses in a list and check the list for the addresses to see if they existed or not. However this requires an O(n) search, which isn't exactly what I am wanting. So instead if I used a check for deallocation method, I can go for an O(1) time check and reduce the total time it would take to check for memory allocation/deallocation.

View 11 Replies View Related

C/C++ :: Checking For A Space In Scanf

Jan 23, 2014

I have created a prompt which prompts the user for an integer and I have set up a loop to check for if it is an integer or not. My "bug" is that a user can enter an "integer" and "space" and "enter" and it does not give any error and assumes that "All is FINE!". I have gotten the value from the ascii table of 'SPACE' and put it as a check in my parameter of while, but it does not work.

Here is my code:

int x, y, boolean, i;
char buff[256];
printf("Enter the first integer value: ");
scanf("%s", buff);
i = 0;
boolean = 0; //initializing our boolean var that will eventually decide if we have an error or not

[code]....

View 4 Replies View Related

C/C++ :: Checking Typename In Templates

Mar 6, 2014

Suppose you have a templated class, such as

template <typename T>
class Matrix {
// some stuff and some methods
};

and let's say that you have some methods that need to do some type-dependent stuff, like, for example,

template <typename T>
Matrix<T> Matrix<T>::transpose() const {
// get this->rowCount, this->columnCount
// create a Matrix that has rowCount amount of columns and columnCount amount of rows
// copy (*this)[j][k] to theMatrix[k][j] (for all of the entries in *this)
// if the entries are complex, take the complex conjugate of them all
}

Would it be good practice to check explicitly for the typename parameter (or is this, somehow, defeating the purpose of templates)? std::cout << "I know that this is a design question, but it needs to be asked... ";

View 1 Replies View Related

C/C++ :: Strtok And Null Checking?

Mar 1, 2015

I'm playing around with parts of code and am coming across some errors. Most of my concern is related to strtok(). I've used it before but with a char* named token. I used a while loop to continuously check whether token was equal to NULL. In the following code, however, there aren't any checks. I was wondering if that is why this code prints (null) while running. Also, I would like to know if it is possible to read input like this code attempts to do - assigning tokens to each variable one after the other.

The format of the input:

Zucchini, Squash, pound
Yellow, Squash, pound
Tomatoes, Ugly Ripe, each
#include <stdio.h>
#include <stdlib.h>

[code]....

View 3 Replies View Related

C++ :: Checking Type With Iterators

Oct 13, 2013

Assuming I have a list of pointers to a generic type T:

#include <vector>
//...
list<T*> myList;

Now assuming I want to go on the list, and if T's type is matched to the type I'm looking for, then cast it to this type and do something. List shown here:

list<T*>:: const_iterator iter= myList.begin();
for(; iter!=myList.end(); ++iter){
if( typeid(*iter)==typeid(Something*)) //RUN-TIME ERROR
dynamic_cast<Something*>(*iter)->DoSomething();
}

how do I fix this run-time error?

View 1 Replies View Related

C++ :: Checking To See If Integer Is A Character

Feb 14, 2014

#include <iostream>
using namespace std;
int main(){
int x;
cout << "Enter character:";
cin >> x;

[Code] ....

If i type in:
+
How come it says that "this is not addition?

View 5 Replies View Related

C Sharp :: Checking If ID And Reg Already Exists

Jun 5, 2013

I have this table Profile which has fields with user_Id and regNo and I want to check first if id and email are already exists before proceed to inserting datas. In my codes, I am able to validate only one row (either id or reg number), but if I am going to validate the two of them, it gives me an error, saying "Must declare the scalar variable @userid". I dont know if it is with my select that is wrong or something in my codes

SqlConnection con = new SqlConnection("Data Source=GATE-PCSQLEXPRESS;Initial Catalog=dbProfile;Integrated Security=True");
    con.Open();
    SqlCommand cmdd = new SqlCommand("select * from Profile where user_Id = @userid AND RegNo = @reg", con);  
    SqlParameter param = new SqlParameter();

[Code] .....

View 3 Replies View Related

C++ :: Checking For IDConfig In Makefile?

Mar 29, 2012

How do I check for ldconfig in a makefile? This makefile errors because it tries to run ldconfig, even though OS = Darwin

Code:
ifeq ($(SHARED),1)
install: banner install_headers $(lib_target)
@echo "Install shared library"
cp -f ./$(lib_target) $(inst_path)
cd $(inst_path) ;

[Code] ....

Errors

Code:
/bin/sh: -c: line 0: syntax error near unexpected token `Darwin,Darwin'
/bin/sh: -c: line 0: `ifneq (Darwin,Darwin)'
make: *** [install] Error 2
make: ldconfig: No such file or directory
make: *** [uninstall] Error 1

View 3 Replies View Related

Visual C++ :: Checking Denominator Zero Value

Dec 21, 2012

To calculate line slope I am using formula ,

line_slope = (meanxy - (meanx * meany)) / (meanyy) - (meany * meany));

All the variables are floats.

How to check whether the denominator .. (meanyy)- (meany * meany)) is zero ? Cause its float.

can I check with ..

float f1 = (meanyy) - (meany * meany) ;

if (f1 == 0.0) ..

Will this work surely ? I am using this formula in project based on winXP but it survived. As soon as I ported the code on DPMI based code , I observed a system hang after some time if all the points I supply are (0,0) while drawing a line.

View 3 Replies View Related

C++ :: Checking If A Filestream Was Properly Opened

Apr 9, 2013

I' used to check if my streams are properly opened with a simple:

Code:
if (!file)
std::cout<<"Error message";

However I just realized this is only a valid test if they are initialized with a wrong string and when I tested it:

Code:
int main() {
ifstream f_one("input.txt");
ifstream f_two("not_a_file.txt");
ifstream f_three;

[Code] ....

I didn't get the f_three error message, only the f_two.

how should I check my streams in order to prevent this?

View 6 Replies View Related

C :: Checking What User Has Entered (City)

Mar 9, 2013

I am using Dev C++ on a windows computer.

In my code, the user enters the name of a city, and then according to what city it is, the program displays the coordinates of that city

I can't find a way of figuring out and checking which city the user has entered so the code can displays its appropriate latitude and longitude.

View 9 Replies View Related

C# :: Tool For Checking Functions In Assembly?

Oct 15, 2012

is there a tool to find all functions and classes in an assembly?

View 3 Replies View Related

C :: Checking How Many Bytes Are Remaining In A File?

Feb 22, 2013

while bytesremaining >=8 do something;
if bytesremaing <8 then something else .

I am new and don't know how to code for this.

View 2 Replies View Related

C :: Reading String And Checking If Integer

Nov 23, 2013

wrote this program to check if a string is an integer. It checks for + or - sign at the front of it, but it spat out some errors.I think I broke it.Here is the code:

Code:

#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
int getInteger(char*);
int main(void) {
char str[99];
int x;
}

[code].....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved