![]() ���߼�飺 ������ѧ�о�������ͼ���ԡ�ʮ��������Linux����ķ�չ��ѧ�� ��΢���޹ص��κ�����������޹ص���������辰�����㡣 ���ģ� |
ժҪ��Abstract
����Rendermanϵ�еĵ���ƪ���� ( Renderman I Renderman II ), �������ǽ���������Ҫ�����⣺ʹ�á�C����C++������ ���ģ�ͺͲ���һ����Ŀ����ԡ�
��ǰ�ƪ�����пɺ�����ؿ���ֱ��ͨ�����һ���ı��ļ� ����һ����ǿ��ܵģ�����Ͼ�̫����ζ�� ���磬����дһ��.rib���ļ������һ����Ծ������˶��� ������һЩ�����ǿ�����д�������ģ�ͺͶ����ġ�C���ԡ���C++���ԡ� Ӧ�ó��򣬲����ô��͡�.rib������׼�����û��Զ��庯�� UNIX�Ĺܵ���������ֱ�Ӵ�����ɵ�Renderman��������� ����rendrib��rendribv��rgl���� �����ض��򵽡�.rib���ļ���
������ǰ��װ���������ɫ���ߣ�Blue Moon Rendering Tools�� ���������Ϊlib��include����Ŀ¼�� ���ĸ��ļ�������ֻ�漰�����е����ri.hͷ�ļ��� libribout.a����⡣ͷ�ļ�Ӧ�ÿ�����/use/local/includeĿ¼�� libribout.a������/use/local/libĿ¼���о���Ķ��߿��� ѡ��װ������λ�ã�����װ������ǿ�ʼ׼����һ�����ӳ���
���ǵĵ�һ��������ʾʮ�ֻ��Renderman��̡����κ�C����һ�� ����ʹ�ÿ�֮ǰ�������Ӧ��ͷ�ļ����������ri.h�� ���⣬���DZ��뽫����Ϳ�������ӣ�
gcc myprogram.c -o myprogram -lribout -lm
������һ������ڿ���̨�ϼ����ʱ������� Makefile
LIBS = -lm -lribout
PROGNAME = primero
all: $(PROGNAME)
$(PROGNAME).o: $(PROGNAME).c
gcc -c $(PROGNAME).c
$(PROGNAME): $(PROGNAME).o
gcc -o $(PROGNAME) $(PROGNAME).o $(LIBS)
|
���ǵĵ�һ�����ӽ������뽨�һЩ����ᣬһ�����壬�ļ���Ϊ primero.c��������Դ���룺
1 #include <stdio.h>
2 #include <math.h>
3 #include <ri.h>
4
5 void main(void)
6 {
7 int i;
8 int x,y,z;
9 int nf;
10 float slopex,slopey,slopez;
11
12 RtColor Rojo={1,0,0};
13 RtColor Verde={0,1,0};
14 RtColor Azul={0,0,1};
15 RtColor Blanco={1,1,1};
16
17 RtPoint p1={30,0,10}; /* Posicicion inicial de la pelota */
18 RtPoint p2={0,20,10}; /* Posicion final de la pelota */
19
20 RtPoint from={0,100,100}; /* Direccion de la luz */
21 RtPoint to={0,0,0};
22
23 char name[]="primero.tif";
24 RtFloat fov=45;
25 RtFloat intensity1=0.1;
26 RtFloat intensity2=1.5;
27 RtInt init=0,end=1;
28
29 RiBegin(RI_NULL);
30 RiFormat(320,240,1);
31 RiPixelSamples(2,2);
32 RiShutter(0,1);
33 RiFrameBegin(1);
34 RiDisplay(name,"file","rgb",RI_NULL);
35 name[7]++;
36 RiProjection("perspective","fov",&fov,RI_NULL);
37 RiTranslate(0,-5,60);
38 RiRotate(-120,1,0,0);
39 RiRotate(25,0,0,1);
40 RiWorldBegin();
41 RiLightSource("ambientlight","intensity",&intensity1,RI_NULL);
42 RiLightSource("distantlight","intensity",&intensity2,"from",from,"to",to,RI_NULL);
43 RiColor(Azul);
44 RiTransformBegin();
45 RiCylinder(1,0,20,360,RI_NULL);
46 RiTranslate(0,0,20);
47 RiCone(2,2,360,RI_NULL);
48 RiTransformEnd();
49 RiColor(Verde);
50 RiTransformBegin();
51 RiRotate(-90,1,0,0);
52 RiCylinder(1,0,20,360,RI_NULL);
53 RiTranslate(0,0,20);
54 RiCone(2,2,360,RI_NULL);
55 RiTransformEnd();
56 RiColor(Rojo);
57 RiTransformBegin();
58 RiRotate(90,0,1,0);
59 RiCylinder(1,0,20,360,RI_NULL);
60 RiTranslate(0,0,20);
61 RiCone(2,2,360,RI_NULL);
62 RiTransformEnd();
63 RiColor(Blanco);
64 RiSphere(5,-5,5,360,RI_NULL);
65 RiWorldEnd();
66 RiFrameEnd();
67 RiEnd();
68 };
|
��
ǰ�����ǻ��ͷ�ļ�������ri.h��Renderman���ͷ���塣 ÿ��Renderman������ri.h������ȼ۵ģ�����ã����� TransformBegin����ں���RiTransformBegin()�ȵȡ� ����make������ִ�е�primero�����ǵ����� ִ��ʱ����ͨ���ض���primero > primero.rib���� ֱ�Ӵ�����������̣�primero | rendrib������������ļ��� �ں�һ������У�rendrib�������һ����ɫ����ļ�primero.tif��
�ӿ�����õĺ�����봦��RiBegin(RI_NULL)��RiEnd()����֮�䡣 ���ݸ�RiBegin�IJ���ͨ����RI_NULL�� Ϊ�˷�ֹRIB����׼������ǿ��Դ�������ļ��� * ��"myfile.rib"���� ����һ��������rendrib�������ִ�н�����Renderman�������ɫ�� �����봴��һ���м�RIB�ļ���
���ǵ�һ�����ӵ�Դ�������͵�Cָ�����Renderman�ӿڹ��е����ͺͺ��� ����RtColor�Ǻ����ʵ��ֵ�������ֱ����ɫ����ɫ���ɫ ����Χ��0.0 ��1.0 ��������RtPoint����ռ�λ�ã�RtFloat ��RtInt�ֱ���ʵ����������͡�
��29�а�һ��RiBegin(RI_NULL)�ĵ��ã�����������ǰ����� ��Renderman�ӿڵij�ʼ�����á������↑ʼ��ͨ���������� Ӧ������һ����͵�RIB�ļ����������д��룬��������ض���һ���ļ� ��./primero > primero.rib���������Ӧ������
##RenderMan RIB-Structure 1.0 version 3.03 Format 320 240 1 PixelSamples 2 2 Shutter 0 1 FrameBegin 1 Display "camara.tif" "file" "rgb" Projection "perspective" "fov" [45 ] Translate 0 -5 60 Rotate -120 1 0 0 Rotate 25 0 0 1 WorldBegin LightSource "ambientlight" 1 "intensity" [0.1 ] LightSource "distantlight" 2 "intensity" [1.5 ] "from" [0 100 100] "to" [0 0 0] Color [0 0 1] TransformBegin Cylinder 1 0 20 360 Translate 0 0 20 Cone 2 2 360 TransformEnd Color [0 1 0] TransformBegin Rotate -90 1 0 0 Cylinder 1 0 20 360 Translate 0 0 20 Cone 2 2 360 TransformEnd Color [1 0 0] TransformBegin Rotate 90 0 1 0 Cylinder 1 0 20 360 Translate 0 0 20 Cone 2 2 360 TransformEnd Color [1 1 1] Sphere 5 -5 5 360 WorldEnd FrameEnd |
���ǵĵ�һ�����Ӳ���ʮ�����á�Ϊ�������һ��������DZ���дһ�� �µij���������ƵIJ������������������ڶ���������ϡ� ��һ��������ֻ��һ������ɣ������������Ҫʹ�����ƶ���
�ڶ��������У����ǵij������������������һ��������ɣ� �����彫����꣨20��0��10���ƶ�����0��20��10������ �Ӽ������Ļ���Ҷ��ƶ�����ˡ�λ��ʹ��RtPoint�ṹ���壨18��19�У��� ������������ͼ�����������ڱ��nf�С� ʹ��������ʼ����ֹλ�ã����Լ����ÿ����������ϵIJ��� ��slopex��slopey��slopez������Щ���������� ��ĺ�����޸�����λ�������������Ϣ���ڵ�75��78��֮�䣬 TransformBegin/TransformEnd�����������λ�á� ÿһ���µ�λ�ý��ڵ�76���н��м򵥵ؼ��㡣
1 #include <stdio.h>
2 #include <math.h>
3 #include <ri.h>
4 #include "filename.h"
5
6 void main(void)
7 {
8 int i;
9 int x,y,z;
10 int nf;
11 float slopex,slopey,slopez;
12
13 RtColor Rojo={1,0,0};
14 RtColor Verde={0,1,0};
15 RtColor Azul={0,0,1};
16 RtColor Blanco={1,1,1};
17
18 RtPoint p1={30,0,10}; /* Posicicion inicial de la pelota */
19 RtPoint p2={0,20,10}; /* Posicion final de la pelota */
20
21 RtPoint from={0,100,100}; /* Direccion de la luz */
22 RtPoint to={0,0,0};
23
24 char base[]="camara_";
25 char ext[]="tif";
26 char name[50];
27 RtFloat fov=45;
28 RtFloat intensity1=0.1;
29 RtFloat intensity2=1.5;
30 RtInt init=0,end=1;
31
32 nf=100; /* Numero de frames */
33 slopex=(p2[0]-p1[0])/nf;
34 slopey=(p2[1]-p1[1])/nf;
35 slopez=(p2[2]-p1[2])/nf;
36
37 RiBegin(RI_NULL);
38 RiFormat(320,240,1);
39 RiPixelSamples(2,2);
40 RiShutter(0,1);
41 for (i=1;i <= nf;i++)
42 {
43 RiFrameBegin(i);
44 filename(base,ext,sizeof(base)+4,i-1,name);
45 RiDisplay(name,"file","rgb",RI_NULL);
46 name[7]++;
47 RiProjection("perspective","fov",&fov,RI_NULL);
48 RiTranslate(0,-5,60);
49 RiRotate(-120,1,0,0);
50 RiRotate(25,0,0,1);
51 RiWorldBegin();
52 RiLightSource("ambientlight","intensity",&intensity1,RI_NULL);
53 RiLightSource("distantlight","intensity",&intensity2,"from",from,"to",to,RI_NULL);
54 RiColor(Azul);
55 RiTransformBegin();
56 RiCylinder(1,0,20,360,RI_NULL);
57 RiTranslate(0,0,20);
58 RiCone(2,2,360,RI_NULL);
59 RiTransformEnd();
60 RiColor(Verde);
61 RiTransformBegin();
62 RiRotate(-90,1,0,0);
63 RiCylinder(1,0,20,360,RI_NULL);
64 RiTranslate(0,0,20);
65 RiCone(2,2,360,RI_NULL);
66 RiTransformEnd();
67 RiColor(Rojo);
68 RiTransformBegin();
69 RiRotate(90,0,1,0);
70 RiCylinder(1,0,20,360,RI_NULL);
71 RiTranslate(0,0,20);
72 RiCone(2,2,360,RI_NULL);
73 RiTransformEnd();
74 RiColor(Blanco);
75 RiTransformBegin();
76 RiTranslate(p1[0]+slopex*(i-1),p1[1]+slopey*(i-1),p1[2]+slopez*(i-1));
77 RiSphere(5,-5,5,360,RI_NULL);
78 RiTransformEnd();
79 RiWorldEnd();
80 RiFrameEnd();
81 }
82 RiEnd();
83 };
|
�����������������ǰһ������ڶ������ӣ����벢ִ�У���Ϊ���� �ض������rendribv�����������ǿɽ��ܵ����ʿ��� Ԥ�����ǵĶ�����һ����׷�����Ϊ���rib����ļ������ͱ�׼���һ�����ļ��� ������Է�����ɵ��ļ���ʮ���Ӵ�� (segundo.ribռ70kb) ��������Ϊͬһ���������100�Σ�ÿ������һ�Σ�
�����ͼ������һЩ�������мä»ï¿½æ£º
��Ȼ������ʹ����ϣ����κ����ﶯ����������λ�ã� ��С����ǿ�ȣ������ʹ����������ԡ���
�����һ�������У���������������ʹ����ӵ��Ϸ�������� �������ȶ��庯��rebote()����������˼������������ ��ǰ����������ÿ�η����Ļ����������ܴﵽ�����߶ȡ� ��������ʵ�֣�
float rebote (int i, int nframes, int max)
{
float min, z;
while (i > nframes) i-=nframes;
min=sqrt(max);
z=i-((float)nframes/2.0);
z=(z*min)/((float)nframes/2.0);
z=(float)max - (z*z);
return(z);
}
|
����һЩ�򵥵ļ��㣬����ӳ����͵���������(y=x^2)�� �������ϣ������߶ȡ������ͼ����һЩ�ɳ�����ɵ� ÿ�η������м�ͼ�� tercero.c:
���ṩһЩ����GIF�ļ��������ʾ������̣���Ȼ�������л��� ��������Netscape����������ͨ��xanim��Ӧ���ܹ� ��ؿ�����
���������˶���segundo_anim.gif
�������˶��� tercero_anim.gif
�������ǹ���Renderman��C���Խӿڻ�������̸�һ���䡣 ��߼�����׳�۵ı����������Ӱ(shaders)�� ï¿½ï¿½ï¿½á¹©ï¿½Ë³ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½É«ï¿½Ä¸ï¿½ï¿½ï¿½Æ£ï¿½ï¿½ï¿½Îªï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½Ç¿ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½í£¬ï¿½ï¿½ï¿½ï¿½ÈµÈ¡ï¿½
���룺Miguel A Sepulveda
| ��ҳ��LinuxFocus�à¼ï¿½ï¿½Î¬ï¿½ï¿½ © Carlos Calzada Grau LinuxFocus 1999 |