フロント クリッピング プレーンの近くに OpenGL でオブジェクトを描画しようとしています。既にパスが定義されており、カメラがパスを下って移動しています。今、カメラで動いているオブジェクトを描きたいのですが、ボットは正面のクリッピング面に直接ありません。
私はAndroid でTux Racerゲーム ポートを使用しており、hud.c で次のような小さなテスト機能を試しました。
void draw_triangle() {
set_gl_options(FOG_PLANE);
glPushMatrix();
{
glTranslatef(getparam_x_resolution() / 2.0, getparam_y_resolution() / 2.0, -5.0);
glBegin(GL_TRIANGLES); // Drawing Using Triangles
glVertex3f(0.0f, 50.0f, 0.0f); // Top
glVertex3f(-50.0f, -50.0f, 0.0f); // Bottom Left
glVertex3f(50.0f, -50.0f, 0.0f); // Bottom Right
glEnd(); // Finished Drawing
}
glPopMatrix();
}
しかし、それは描きません。どこが間違っていますか?z 軸の -5.0 が遠すぎる場合、または に他のオプションを使用する必要がある場合、私は黙っていません。つまり、set_gl_options()
3D オブジェクトを表示するには、このオプションから何を有効/無効にする必要があるかわかりません。
- GL_TEXTURE_2D
- GL_DEPTH_TEST
- GL_CULL_FACE
- GL_ライティング
- GL_NORMALIZE
- GL_ALPHA_TEST
- GL_BLEND
- GL_STENCIL_TEST
- GL_TEXTURE_GEN_S
- GL_TEXTURE_GEN_T
- GL_COLOR_MATERIAL
その他の機能:
- glDepthMask
- glShadeModel
- glDepthFunc
カメラビューを設定するコードは次のとおりです。
void update_view(player_data_t *plyr, scalar_t dt) {
point_t view_pt;
vector_t view_dir, up_dir, vel_dir, view_vec;
scalar_t ycoord;
scalar_t course_angle;
vector_t axis;
matrixgl_t rot_mat;
vector_t y_vec;
vector_t mz_vec;
vector_t vel_proj;
quaternion_t rot_quat;
scalar_t speed;
vector_t vel_cpy;
scalar_t time_constant_mult;
vel_cpy = plyr->vel;
speed = normalize_vector(&vel_cpy);
time_constant_mult =
1.0
/ min( 1.0,
max( 0.0,
( speed - NO_INTERPOLATION_SPEED ) /
( BASELINE_INTERPOLATION_SPEED - NO_INTERPOLATION_SPEED )));
up_dir = make_vector(0, 1, 0);
vel_dir = plyr->vel;
normalize_vector(&vel_dir);
course_angle = get_course_angle();
switch (plyr->view.mode) {
case TUXEYE: {
.
.
.
break;
}
case BEHIND: {
/* Camera-on-a-string mode */
/* Construct vector from player to camera */
view_vec = make_vector(0, sin(ANGLES_TO_RADIANS(
course_angle -
CAMERA_ANGLE_ABOVE_SLOPE +
PLAYER_ANGLE_IN_CAMERA )), cos(ANGLES_TO_RADIANS(
course_angle -
CAMERA_ANGLE_ABOVE_SLOPE +
PLAYER_ANGLE_IN_CAMERA )));
view_vec = scale_vector(CAMERA_DISTANCE, view_vec);
y_vec = make_vector(0.0, 1.0, 0.0);
mz_vec = make_vector(0.0, 0.0, -1.0);
vel_proj = project_into_plane(y_vec, vel_dir);
normalize_vector(&vel_proj);
/* Rotate view_vec so that it places the camera behind player */
rot_quat = make_rotation_quaternion(mz_vec, vel_proj);
view_vec = rotate_vector(rot_quat, view_vec);
/* Construct view point */
view_pt = move_point(plyr->pos, view_vec);
/* Make sure view point is above terrain */
ycoord = find_y_coord(view_pt.x, view_pt.z);
if (view_pt.y < ycoord + MIN_CAMERA_HEIGHT) {
view_pt.y = ycoord + MIN_CAMERA_HEIGHT;
}
/* Interpolate view point */
if (plyr->view.initialized) {
/* Interpolate twice to get a second-order filter */
int i;
for (i = 0; i < 2; i++) {
view_pt = interpolate_view_pos(plyr->pos, plyr->pos,
MAX_CAMERA_PITCH, plyr->view.pos, view_pt,
CAMERA_DISTANCE, dt,
BEHIND_ORBIT_TIME_CONSTANT * time_constant_mult);
}
}
/* Make sure interpolated view point is above terrain */
ycoord = find_y_coord(view_pt.x, view_pt.z);
if (view_pt.y < ycoord + ABSOLUTE_MIN_CAMERA_HEIGHT) {
view_pt.y = ycoord + ABSOLUTE_MIN_CAMERA_HEIGHT;
}
/* Construct view direction */
view_vec = subtract_points(view_pt, plyr->pos);
axis = cross_product(y_vec, view_vec);
normalize_vector(&axis);
make_rotation_about_vector_matrix(rot_mat, axis,
PLAYER_ANGLE_IN_CAMERA);
view_dir = scale_vector(-1.0, transform_vector(rot_mat, view_vec));
/* Interpolate orientation of camera */
if (plyr->view.initialized) {
/* Interpolate twice to get a second-order filter */
int i;
for (i = 0; i < 2; i++) {
interpolate_view_frame(plyr->view.up, plyr->view.dir, &up_dir,
&view_dir, dt, BEHIND_ORIENT_TIME_CONSTANT);
up_dir = make_vector(0.0, 1.0, 0.0);
}
}
break;
}
case FOLLOW: {
/* Camera follows player (above and behind) */
up_dir = make_vector(0, 1, 0);
/* Construct vector from player to camera */
view_vec = make_vector(0, sin(ANGLES_TO_RADIANS(
course_angle -
CAMERA_ANGLE_ABOVE_SLOPE +
PLAYER_ANGLE_IN_CAMERA )), cos(ANGLES_TO_RADIANS(
course_angle -
CAMERA_ANGLE_ABOVE_SLOPE +
PLAYER_ANGLE_IN_CAMERA )));
view_vec = scale_vector(CAMERA_DISTANCE, view_vec);
y_vec = make_vector(0.0, 1.0, 0.0);
mz_vec = make_vector(0.0, 0.0, -1.0);
vel_proj = project_into_plane(y_vec, vel_dir);
normalize_vector(&vel_proj);
/* Rotate view_vec so that it places the camera behind player */
rot_quat = make_rotation_quaternion(mz_vec, vel_proj);
view_vec = rotate_vector(rot_quat, view_vec);
/* Construct view point */
view_pt = move_point(plyr->pos, view_vec);
/* Make sure view point is above terrain */
ycoord = find_y_coord(view_pt.x, view_pt.z);
if (view_pt.y < ycoord + MIN_CAMERA_HEIGHT) {
view_pt.y = ycoord + MIN_CAMERA_HEIGHT;
}
/* Interpolate view point */
if (plyr->view.initialized) {
/* Interpolate twice to get a second-order filter */
int i;
for (i = 0; i < 2; i++) {
view_pt = interpolate_view_pos(plyr->view.plyr_pos, plyr->pos,
MAX_CAMERA_PITCH, plyr->view.pos, view_pt,
CAMERA_DISTANCE, dt,
FOLLOW_ORBIT_TIME_CONSTANT * time_constant_mult);
}
}
/* Make sure interpolate view point is above terrain */
ycoord = find_y_coord(view_pt.x, view_pt.z);
if (view_pt.y < ycoord + ABSOLUTE_MIN_CAMERA_HEIGHT) {
view_pt.y = ycoord + ABSOLUTE_MIN_CAMERA_HEIGHT;
}
/* Construct view direction */
view_vec = subtract_points(view_pt, plyr->pos);
axis = cross_product(y_vec, view_vec);
normalize_vector(&axis);
make_rotation_about_vector_matrix(rot_mat, axis,
PLAYER_ANGLE_IN_CAMERA);
view_dir = scale_vector(-1.0, transform_vector(rot_mat, view_vec));
/* Interpolate orientation of camera */
if (plyr->view.initialized) {
/* Interpolate twice to get a second-order filter */
int i;
for (i = 0; i < 2; i++) {
interpolate_view_frame(plyr->view.up, plyr->view.dir, &up_dir,
&view_dir, dt, FOLLOW_ORIENT_TIME_CONSTANT);
up_dir = make_vector(0.0, 1.0, 0.0);
}
}
break;
}
case ABOVE: {
/* Camera always uphill of player */
up_dir = make_vector(0, 1, 0);
/* Construct vector from player to camera */
view_vec = make_vector(0, sin(ANGLES_TO_RADIANS(
course_angle -
CAMERA_ANGLE_ABOVE_SLOPE+
PLAYER_ANGLE_IN_CAMERA )), cos(ANGLES_TO_RADIANS(
course_angle -
CAMERA_ANGLE_ABOVE_SLOPE+
PLAYER_ANGLE_IN_CAMERA )));
view_vec = scale_vector(CAMERA_DISTANCE, view_vec);
/* Construct view point */
view_pt = move_point(plyr->pos, view_vec);
/* Make sure view point is above terrain */
ycoord = find_y_coord(view_pt.x, view_pt.z);
if (view_pt.y < ycoord + MIN_CAMERA_HEIGHT) {
view_pt.y = ycoord + MIN_CAMERA_HEIGHT;
}
/* Construct view direction */
view_vec = subtract_points(view_pt, plyr->pos);
make_rotation_matrix(rot_mat, PLAYER_ANGLE_IN_CAMERA, 'x');
view_dir = scale_vector(-1.0, transform_vector(rot_mat, view_vec));
break;
}
case BIRDEYE: {
/* Camera always uphill of player */
up_dir = make_vector(0, 1, 0);
/* Construct vector from player to camera */
/*sin(ANGLES_TO_RADIANS(
course_angle -
CAMERA_ANGLE_ABOVE_SLOPE+
PLAYER_ANGLE_IN_CAMERA ))
*/
/*cos(ANGLES_TO_RADIANS(
course_angle -
CAMERA_ANGLE_ABOVE_SLOPE+
PLAYER_ANGLE_IN_CAMERA ))
*/
view_vec = make_vector(0, 3, -0.5);
view_vec = scale_vector(CAMERA_DISTANCE, view_vec);
/* Construct view point */
view_pt = move_point(plyr->pos, view_vec);
/* Make sure view point is above terrain */
ycoord = find_y_coord(view_pt.x, view_pt.z);
if (view_pt.y < ycoord + MIN_CAMERA_HEIGHT) {
view_pt.y = ycoord + MIN_CAMERA_HEIGHT;
}
/* Construct view direction */
view_vec = subtract_points(view_pt, plyr->pos);
make_rotation_matrix(rot_mat, PLAYER_ANGLE_IN_CAMERA, 'x');
view_dir = scale_vector(-1.0, transform_vector(rot_mat, view_vec));
break;
}
default:
code_not_reached();
break;
}
/* Create view matrix */
plyr->view.pos = view_pt;
plyr->view.dir = view_dir;
plyr->view.up = up_dir;
plyr->view.plyr_pos = plyr->pos;
plyr->view.initialized = True;
setup_view_matrix(plyr);
}
アップデート
解決しました!、問題は OpenGL ES の代わりに OpenGL を使用することにありました。