CS 497: Computer Graphics

Download Report

Transcript CS 497: Computer Graphics

CS 497: Computer
Graphics
James Money
Copyright  1999 by James H. Money. All rights reserved. Except as permitted under United States Copyright Act of 1976, no part of this publication may be
reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the author.
Object Collision
What happens if a viewer
walks into an object right
now?
Copyright  1999 by James H. Money. All rights reserved. Except as permitted under United States Copyright Act of 1976, no part of this publication may be
reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the author.
Object Collision
You walk right through the
object!
Copyright  1999 by James H. Money. All rights reserved. Except as permitted under United States Copyright Act of 1976, no part of this publication may be
reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the author.
Object Collision
What do we need to determine when a
view comes in contact with an existing
object?
We need to determine the intersection
of two volumes.
Copyright  1999 by James H. Money. All rights reserved. Except as permitted under United States Copyright Act of 1976, no part of this publication may be
reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the author.
Object Collision
However, intersecting objects is an expensive
operation. If we operate on bounding
volumes, we can make this a simple
operation. We just can check the bounding
coordinates of the object’s volume!
Copyright  1999 by James H. Money. All rights reserved. Except as permitted under United States Copyright Act of 1976, no part of this publication may be
reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the author.
Object Collision
Boolean Intersect(Object1 *obj1,Object2 *obj2){
if ((obj1->minX < obj2->minX) && (obj1->maxX > obj2->minX))
|| ((obj1->minX < obj2->maxX) &&(obj1->maxX > obj2->maxX)){
if ((obj1->minY<obj2->minY)&&(obj1->maxY>obj2->minY))
|| ((obj1->minY<obj2->maxY) &&(obj1->maxY>obj2->maxY)){
if ((obj1->minZ < obj2->minZ) && (obj1->maxZ > obj2->minZ))
|| ((obj1->minZ < obj2->maxZ) &&(obj1->maxZ > obj2->maxZ)){
return TRUE;
}
}
}
if ((obj2->minX < obj1->minX) && (obj2->maxX > obj1->minX))
|| ((obj2->minX < obj1->maxX) &&(obj2->maxX > obj1->maxX)){
if ((obj2->minY<obj1->minY)&&(obj2->maxY>obj1->minY))
|| ((obj2->minY<obj1->maxY) &&(obj2->maxY>obj1->maxY)){
if ((obj2->minZ < obj1->minZ) && (obj2->maxZ > obj1->minZ))
|| ((obj2->minZ < obj1->maxZ) &&(obj2->maxZ > obj1->maxZ)){
return TRUE;
}
}
}
return FALSE;
}
Copyright  1999 by James H. Money. All rights reserved. Except as permitted under United States Copyright Act of 1976, no part of this publication may be
reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the author.
Object Collision
int Polygon3D::PtInPolygon(Point3D &pt){
double total=pt.x*N->v[0] + pt.y*N->v[1] + pt.z*N->v[2] + N->v[3];
if (fabs(total) > 0.5E-5) return FALSE;
int numEdges=0; double tx,ty,tz;
for(int I=0;I<(numPoints-1);I++){
tx=(pt.x - pts[I].x)/(pts[I+1].x + pt.x - pts[I].x - maxX);
ty=(pt.y - pts[I].y)/(pts[I+1].y + pt.x - pts[I].y - maxY);
tz=(pt.z - pts[I].z)/(pts[I+1].z + pt.z - pts[I].z - maxZ);
if (((tx>=0.5E-5) && (tx<=1.000005)) &&
((ty>=0.5E-5) && (ty<=1.000005)) &&
((tz>=0.5E-5) && (tz<=1.000005))) numEdges++;
}
tx=(pt.x - pts[numPoints-1].x)/
(pts[0].x + pt.x - pts[numPoints-1].x - maxX);
ty=(pt.y - pts[numPoints-1].y)/
(pts[0].y + pt.x - pts[numPoints-1].y - maxY);
tz=(pt.z - pts[numPoints-1].z)/
(pts[0].z + pt.z - pts[numPoints-1].z - maxZ);
if (((tx>=0.5E-5) && (tx<=1.000005)) &&
((ty>=0.5E-5) && (ty<=1.000005)) &&
((tz>=0.5E-5) && (tz<=1.000005))) numEdges++;
if (numEdges & 1) return TRUE;
return FALSE;
}
Copyright  1999 by James H. Money. All rights reserved. Except as permitted under United States Copyright Act of 1976, no part of this publication may be
reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the author.
Moving Up in the World
Now we can detect if the user runs into an
object in the world. What about stepping
on objects or falling??
For stepping up, we can just check to
see if the user’s height/4.0 is greater
than the height from where you
currently are and the top(Ymax) of the
bounding rectangle of the object.
Copyright  1999 by James H. Money. All rights reserved. Except as permitted under United States Copyright Act of 1976, no part of this publication may be
reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the author.
Falling in the world!
Now for falling, we have to check to see if
the base of of the user object if equal to
the base of some object in the
world.(Remember in intersection that
we don’t check if it’s equal!) We can
make it easy by checking the point at
the middle of the object on the bottom
face of the user.
Copyright  1999 by James H. Money. All rights reserved. Except as permitted under United States Copyright Act of 1976, no part of this publication may be
reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the author.
Falling in the world!
To make things easy, we keep a record of the
last item you were on top of, and check it first.
It the points fits the plane equation for that
polygon, we do nothing. If not, we search for
a polygon in the current room that has a
normal that satisfies this point and save that
polygon for next time. If none exists, we drop
in world Y coordinates by some
value(perhaps 0.2 meters) until we hit a
polygon.
Copyright  1999 by James H. Money. All rights reserved. Except as permitted under United States Copyright Act of 1976, no part of this publication may be
reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the author.
Falling in the world!
To make things even easier, we will not check
an object in the room whose Xmin, Xmax, Ymin,
Ymax are not within our X,Y user position at
the base.
Copyright  1999 by James H. Money. All rights reserved. Except as permitted under United States Copyright Act of 1976, no part of this publication may be
reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the author.