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.
Clipping in 4D
Let’s review our pipeline to see when we clip: 3D Modeling Coordinates 3D World Coordinates View Reference Coordinates Normalized Projection Coordinates 2D Device Coordinates Modeling Transformation View Orientation Matrix View Mapping Matrix Clip, transform into 2D screen coordinates R*T(-VRP) M*S per *SH par *T(-PRP) M vv3dv 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.
Clipping in 4D
We clip after we normalize, but before we project the points.
We need to clip against the normalized view volume for a parallel canonical view volume. The equations for this are: • W>0: -W • W<0: -W X X W, -W W, -W Y Y W, -W W, -W Z Z 0 0 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.
Clipping in 4D
We don’t have to worry about W<0 if we do the following: – If for 2 points the W’s are both >0, do nothing else.
– If for 2 points the W’s are both <0, negate both points first.
– If the 2 points W’s are opposite in sign, clip against the points, negate them, and clip again.
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.
Clipping a 3D polygon
Clipping a polygon is not as easy as clipping the lines that make up the polygon: – There can be more points or less points after the clip.
– If all the points are outside the view volume, but the polygon is visible, then polygon will not be visible.
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.
Clipping a 3D polygon
To clip the polygon: – We must clip each line of the polygon against each view plane separately. This ensures the polygon is visible even if its lines are not.
– We must systematically go through all the planes, left then right, bottom then top, and finally, near then far planes.
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.
Clipping a 3D polygon
} Here’s the pseudocode for one plane: clip_left(double x,y,z,w){ if (this point is on the opposite side of the plane from the previous point){ t=parametric intersection of line of 2 points with the plane; clip_right(x 0 +t*dx,y 0 +t*dy,z 0 +t*dz,w 0 +t*dw); } save previous point for this plane; if (x>-W) clip_right(x,y,z,w); 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.
Parametric form of lines
The parametric form of a line is(extended to include W): – X = X 0 – Y = Y 0 + (X + (Y 1 1 - X 0 )*t - Y 0 )*t – Z = Z 0 + (Z 1 – W = W 0 + (W - Z 1 0 )*t - W 0 )*t Also: – dx = X 1 – dy = Y 1 - X - Y 0 0 – dz = Z 1 – dw = W 1 - Z 0 - W 0 So, given the two points, we can find the intersection with a plane 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.
Equations of the intersections for a plane
X
W
(
x x
0
xt
w
)
t
w
0
w
0
wt
x
0
so the equations are
:
X W t
w
0
x
x
0
w x
0
xt
X Y Z
y
0
z
0
yt
zt X
W
(
x x
0
xt
w
)
t
w
0
w
0
wt
x
0
so the equations are
:
X W Y Z t
w
0
x x
0
x
0
w
xt X y
0
yt z
0
zt
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.
Equations of the intersections for a plane
X
(
y y
0
yt
w
)
t
Y
w
0
w
0
wt
y
0
so the equations are
:
Y W X Z t
w
0
y
y
0
w y
0
Y
yt
z x
0 0
xt
zt Y
(
y y
0
yt
w
)
t
W
w
0
w
0
wt y
0
so the equations are
:
Y W X Z t
w
0
y
y
0
w
Y y
0
yt
x
0
xt z
0
zt
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.
Equations of the intersections for a plane
Z
(
z z
0
w
)
zt t
W
w
0
w
0
wt
z
0
so the equations are
:
Z W X Y t
z
z w
0
z
0
w
zt
0
Z
x y
0 0
xt
yt Z z
0
zt
0 0
so the equations are
:
Z X Y W t
z
0
z
0
x
0
xt y
0
yt w
0
wt
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.
Clipping a 3D polygon
Remember, after you clip the last plane(far plane, Z=-W), you must store the point if it is valid, and not call clip_x again!
Your input should be an array of 4D points, and the output is another array of 4D points, but their sizes don’t have to be the same!
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.