[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
4x1 column vectors. Vector4f
is intended to be used
to represent a vector, and point4f
is to a point,
but as far as OpenGL concerns, both are just an array of four floats,
x, y, z and w.
These classes inherit <sequence>
and <collection>
classes. So if you import gauche.sequence
module,
you can use generic function such as ref
and (setter ref)
to get/set individual elements. The generic version of
map
and for-each
can also be used on the vector4f and
point4f instances.
Aside from the type, the only difference is that the default value of w component— it's 0.0 for vectors, and 1.0 for points. So usual transformation produces expected results; for example point plus vector becomes point, vector plus vector becomes vector, and translating point changes its coordinates but translating vectors doesn't, and so on. However, you can set w component to other value to do nontrivial operations.
#,(vector4f x y z w)
#,(point4f x y z w)
These SRFI-10 syntax can be used to denote literal <vector4f>
and <point4f>
instance, respectively.
The write methods are defined so that the instance is written out in this form, and can be read back later.
Returns true iff obj is vector4f and point4f, respectively.
Creates a vector4f and point4f instance with given values, respectively.
Another way to create a vector4f and a point4f.
The first returns #,(vector4f 0.0 0.0 0.0 0.0)
,
and the latter returns #,(point4f 0.0 0.0 0.0 1.0)
.
Convert a list of three or four real numbers to a vector4f and a point4f, respectively. If l is not a list of three or four real numbers, an error is signalled.
(list->vector4f l) ≡ (apply vector4f l) ≡ (coerce-to <vector4f> l) |
Convert a vector4f and a point4f to a list of four real numbers, respectively.
(vector4f->list v) ≡ (coerce-to <list> v) ≡ (map (cut ref v <>) (iota 4)) |
Creates a vector4f or a point4f, initializing by the elements of f32vector v. V must be longer than 4, and the first four elements are used to initialize the created vector or point.
If optional start argument is given, it specifies an index of v from which the initial values are taken; that is, start, start+1, start+2 and start+3-th elements are used to create a vector or a point. This allows to create vectors from plain float array:
(map (lambda (off) (f32vector->vector4f vec (* off 4))) (iota (/ (size-of vec) 4))) |
The conversion can be done using coerce-to
, as well.
(f32vector->vector4f vec) ≡ (coerce-to <vector4f> vec) |
Convert a vector4f v or a point4f p to four-element f32vector.
(vector4f->f32vector v) ≡ (coerce-to <f32vector> v) |
Returns a new copy of vector4f v or point4f p, respectively.
Destructively sets the content of srcv or srcp to dstv or dstp, respectively.
Sets a real number value to k-th element of a vector4f v or a point4f p.
(vector4f-set! v k value) ≡ (set! (ref v k) value) |
Gets a value of k-th element of a vector4f v or a point4f p. If k is out of range, an error is signalled, unless fallback is provided, in such a case fallback is returned.
(vector4f-ref v k) ≡ (ref v k) |
Returns a dot product of two vector4fs, x and y.
Returns a cross product of two vector4fs, x and y. (w element is ignored).
Returns the norm (length) of the vector v.
Returns a normalized vector of vector4f x.
Vector4f-normalize
allocates a new vector, while
vector4f-normalize!
modifies the original vector.
As a special case, if x is a vector of length 0, a vector of length 0 is returned.
Returns a sum of two vector4fs, x and y. The destructive version modifies x.
Adds a point4f x and a vector4f y, and returns a translated point. The destructive version modifies x.
Subtracts either a vector4f or a point4f y from a point4f x. If y is a vector4f, returns a translated point. If y is a point4f, returns a vector4f from point y to point x.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] |
This document was generated by Shiro Kawai on June, 7 2008 using texi2html 1.78.