• Create Account

# Exessuz

Member Since 28 Jun 2012
Offline Last Active Feb 04 2013 03:14 PM

### #4972750C++: problem erasing vector items

Posted by on 23 August 2012 - 03:09 PM

try something like this, havent t
```
std::vector<int> somevalues;
std::vector<int> somevaluesTocheck;
bool status = false;

for(int i = 0 ; i < (int)somevaluesTocheck.size() ; i++){

status = false;

for(int j = 0; j < (int)somevalues.size(); j++){

if(somevaluesTocheck[i] == somevalues[j]){

status = true;

}

}

if(!status){
somevaluesTocheck.erase(somevaluesTocheck.begin() + i);
}
}
```

### #4972716Raycasting

Posted by on 23 August 2012 - 01:42 PM

I think you should try with ray / plane collision , for example an Axis Aligned box or a OOB

the idea is to cast a ray from the eye or from a click point and check if the ray intersect the plane

a ray is defined by

P= Ro + (Rd*t)

Ro = camera eye for example
Rd = ray dir;
t = distance or time

and a plane (P - Po). n = 0

n = plane normal

(Ro + Rd.t - Po).n = 0
Rd.t.n + (Ro - Po).n = 0

t = (Po - Ro)n / Rd.n

If the line starts outside the plane and is parallel to the plane, there is no intersection. In this case, the above denominator will be zero and the numerator will be non-zero. If the line starts inside the plane and is parallel to the plane, the line intersects the plane everywhere. In this case, both the numerator and denominator above will be zero. In all other cases, the line intersects the plane once and t represents the intersection as the distance along the line from Ro

### #4972705Map Coordinates

Posted by on 23 August 2012 - 01:04 PM

if you want to make a 10 x 10 map , lets say that each tile is 32 x 32 px

i used to make a linear array holding all the tile ids

int width = 32;

short map[100]; -> 10x10

supposing that you are drawing Y first

for(int x =0 ; x < 10; x++){
for(int y =0 ; y < 10; y++){

RENDER()
}
}

int x = click.x / 32;
int y = click.y / 32;

then the tile is

int id = x*width + y;

map[id].selected;

PARTNERS