Line 7... |
Line 7... |
//
|
//
|
// Abstract:
|
// Abstract:
|
// 3D model(Bears) rendering sample program.
|
// 3D model(Bears) rendering sample program.
|
//
|
//
|
// Author:
|
// Author:
|
// Kenji Ishimaru (kenji.ishimaru@prtissimo.com)
|
// Kenji Ishimaru (info.wf3d@gmail.com)
|
//
|
//
|
//======================================================================
|
//======================================================================
|
//
|
//
|
// Copyright (c) 2015, Kenji Ishimaru
|
// Copyright (c) 2015, Kenji Ishimaru
|
// All rights reserved.
|
// All rights reserved.
|
Line 37... |
Line 37... |
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
//
|
//
|
// Revision History
|
// Revision History
|
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <system.h>
|
|
#include "mp_lib.h"
|
|
#include "mp_hwdep.h"
|
#include "mp_hwdep.h"
|
|
#include "mp_lib.h"
|
|
#include <stdio.h>
|
|
|
//#define BLENDER_OBJ_TEST
|
|
|
|
#ifdef BLENDER_OBJ_TEST
|
|
#include "blender_obj.h"
|
|
#else
|
|
#include "bear.h"
|
#include "bear.h"
|
#endif
|
|
|
|
void mp_loop() {
|
void mp_loop() {
|
static float transY = 0.0f;
|
static float transY = 0.0f;
|
static int cframe = 1;
|
static int cframe = 1;
|
static float cScale = 4.0;
|
static float cScale = 4.0;
|
Line 61... |
Line 53... |
int pos_z_l_inc,pos_z_r_inc;
|
int pos_z_l_inc,pos_z_r_inc;
|
unsigned char col;
|
unsigned char col;
|
int i;
|
int i;
|
int frame = 0;
|
int frame = 0;
|
int mat_index;
|
int mat_index;
|
mpClearColor(0.5, 0, 0.4);
|
mpClearColor(0.1, 0.1, 0.0);
|
mpViewport(640, 480);
|
mpViewport(640, 480);
|
mpMatrixMode(MP_PROJECTION);
|
mpMatrixMode(MP_PROJECTION);
|
mpPerspective(30.0, 4.0 / 3.0, 1, 100);
|
mpPerspective(30.0, 4.0 / 3.0, 1, 100);
|
|
|
mpVertexPointer(vtx_array);
|
mpVertexPointer(vtx_array);
|
pos_z_l = 0.0;
|
pos_z_l = 0.0;
|
pos_z_r = 0.0;
|
pos_z_r = 0.0;
|
pos_z_l_inc = 0;
|
pos_z_l_inc = 0;
|
pos_z_r_inc = 0;
|
pos_z_r_inc = 0;
|
col = 0x00;
|
col = 0xff;
|
|
int j;
|
while(1) {
|
while(1) {
|
for (i=0;i<360;i++) {
|
for (i=0;i<360;i++) {
|
printf("frame %d\n",frame++);
|
printf("frame %d\n",frame++);
|
mpClear();
|
mpClear();
|
|
|
mpMatrixMode(MP_MODELVIEW);
|
mpMatrixMode(MP_MODELVIEW);
|
mpLoadIdentity();
|
mpLoadIdentity();
|
mpLookAt(0, 0, 1, 0, 0, 0, 0, 1, 0);
|
mpLookAt(0, 0, 1, 0, 0, 0, 0, 1, 0);
|
mpPushMatrix();
|
|
mpTranslate(0.0, 0.0, -8+pos_z_l);
|
mpTranslate(0.0, 0.0, -8+pos_z_l);
|
mpTranslate(-1.3, 0.0, 0.0);
|
mpTranslate(0.0, 0.0, 0.0);
|
mpRotate(i, 0, 1, 0);
|
mpRotate(i, 0, 1, 0);
|
mpScale(2.0,2.0,2.0);
|
mpScale(2.0,2.0,2.0);
|
//mpRenderColor(1.0,0.0,0.0);
|
|
mpRenderColorU(col);
|
mpRenderColorU(col);
|
mpDrawArrays(num_vtx*3);
|
mpDrawArrays(num_vtx*3);
|
mpPopMatrix();
|
|
mpTranslate(0.0, 0.0, -8+pos_z_r);
|
|
mpTranslate(1.3, 0.0, 0.0);
|
|
mpRotate(i, 0, 1, 0);
|
|
mpScale(2.0,2.0,2.0);
|
|
mpRenderColor(1.0,0.4,0.1);
|
|
//mpRenderColorU(~col);
|
|
mpDrawArrays(num_vtx*3);
|
|
cframe++;
|
cframe++;
|
mpSwapBuffers();
|
mpSwapBuffers();
|
// color
|
|
if (col == 0xff) col = 0;
|
|
else col++;
|
|
// pos_z_l 0:-30
|
|
if (pos_z_l_inc) {
|
|
pos_z_l += 0.1;
|
|
if (pos_z_l > 0.0) {
|
|
pos_z_l_inc = 0;
|
|
}
|
|
} else {
|
|
pos_z_l -= 0.1;
|
|
if (pos_z_l < -30.0) {
|
|
pos_z_l_inc = 1;
|
|
}
|
|
}
|
|
// pos_z_r 0:-30
|
|
if (pos_z_r_inc) {
|
|
pos_z_r += 0.4;
|
|
if (pos_z_r > 0.0) {
|
|
pos_z_r_inc = 0;
|
|
}
|
|
} else {
|
|
pos_z_r -= 0.4;
|
|
if (pos_z_r < -30.0) {
|
|
pos_z_r_inc = 1;
|
|
}
|
|
}
|
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
int main()
|
int main()
|
{
|
{
|
|
|
printf("Hello from Nios II!\n");
|
printf("Bear Demo\n");
|
buffer_clear(0xcdcdcdcd,0);
|
|
buffer_clear(0xdededede,1);
|
|
mpInit();
|
mpInit();
|
|
buffer_clear(0x00000000,0);
|
|
buffer_clear(0x00000000,1);
|
mp_loop();
|
mp_loop();
|
return 0;
|
return 0;
|
}
|
}
|
|
|
|
|