2013年3月24日日曜日

顔のモデリング【女性3】

頬の凸凹をなめらかにしてみた。自分の今のレベルでは輪郭をこれ以上改善できない。もっと色々顔のモデルを見てもっと勉強してからじゃないと、これ以上良い輪郭はできそうにない。なので、次は目と髪を弄くって色々変えてみよう。

2012年9月7日金曜日

顔のモデリング【女性2】

以前作った女性の顔の目と髪を少し変えてみた。 口元も少し笑顔っぽくしてみた。

2012年3月11日日曜日

2012年2月20日月曜日

インテントの使用


インテントの使用例です。

下記はTestIntentActivity.javaです。


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TestIntentActivity extends Activity implements OnClickListener {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
     
        LinearLayout linearLayout = new LinearLayout(this);
     
        TextView textView = new TextView(this);
        textView.setText("トップアクティビティ");
     
        Button button = new Button(this);
        button.setWidth(200);
        button.setHeight(200);
        button.setText("2つ目のアクティビティへ");
        button.setOnClickListener(this);
     
        linearLayout.addView(textView);
        linearLayout.addView(button);
        setContentView(linearLayout);
    }

@Override
public void onClick(View v) {
Intent intent = new Intent(this, Activity01.class);
startActivity(intent);
}
}



下記はActivity01.javaです。



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Activity01 extends Activity implements OnClickListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

LinearLayout linearLayout = new LinearLayout(this);
        
        TextView textView = new TextView(this);
        textView.setText("2つ目のアクティビティ");
        
        Button button = new Button(this);
        button.setWidth(200);
        button.setHeight(200);
        button.setText("トップアクティビティへ");
        button.setOnClickListener(this);
        
        linearLayout.addView(textView);
        linearLayout.addView(button);
        setContentView(linearLayout);
}

@Override
public void onClick(View v) {
Intent intent = new Intent(this, TestIntentActivity.class);
startActivity(intent);
}
}


下記はAndroidManifest.xmlです。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sample.intent"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".TestIntentActivity"
android:launchMode="singleInstance">


            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
        </activity>
        
        <activity android:name="Activity01"  android:launchMode="singleInstance"> </activity>


            
    </application>

</manifest>


2012年2月16日木曜日

SurfaceViewを使ったアニメーション


package com.sample.surface.test;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class SurfaceViewTest01Activity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

AnimationSurfaceView surfaceView;
surfaceView = new AnimationSurfaceView(this);
setContentView(surfaceView);

}


/**
*
* SurfaceViewクラス
* アニメーションを実行する。
*/
public class AnimationSurfaceView extends SurfaceView
implements Runnable, SurfaceHolder.Callback {

static final int SIZE_X = 30;
static final int SIZE_Y = 30;

int positionX = 0;
int positionY = 0;

int screenWidth;
int screenHeight;

SurfaceHolder surfaceHolder;
Thread thread;

public AnimationSurfaceView(Context context) {
super(context);
surfaceHolder = getHolder();
surfaceHolder.addCallback(this);
}

@Override
public void run() {

Canvas canvas = null;
Paint paintBlue  = new Paint();
Paint paintWhite = new Paint();

paintWhite.setStyle(Style.FILL);
paintWhite.setColor(Color.WHITE);

paintBlue.setStyle(Style.FILL);
paintBlue.setColor(Color.BLUE);


while(thread != null){

try{
canvas = surfaceHolder.lockCanvas();

canvas.drawRect(//背景
0,
0,
screenWidth, screenHeight,
paintWhite);

canvas.drawRect(//平行移動する四角形
positionX,
positionY,
positionX + SIZE_X,
positionY + SIZE_Y,
paintBlue);

positionX += 1;//x移動
positionY += 1;//y移動

surfaceHolder.unlockCanvasAndPost(canvas);

}
catch(Exception e){}
}
}

@Override
public void surfaceChanged(
SurfaceHolder holder,
int format,
int width,
int height) {
screenWidth = width;
screenHeight = height;
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
thread = new Thread(this);
thread.start();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
thread = null;
}
}
}

Androidで簡易アニメーション


OpenGLやSurfaceViewを使わずに、簡単にアニメーションさせるにはTranslateAnimationやRotateAnimationを使います。
ここから下はサンプルソースです。


package com.sample.animation;//ここは各自変更して下さい

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

public class AnimationTestActivity extends Activity {//ここも各自変更して下さい
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
     
        //背景になる緑色のレイアウト
        LinearLayout greenLinearLayout = new LinearLayout(this);
        //緑色に設定
        greenLinearLayout.setBackgroundColor(Color.GREEN);
     

        //平行移動するレイアウト
        LinearLayout redLinearLayout = new LinearLayout(this);
        //赤色に設定
        redLinearLayout.setBackgroundColor(Color.RED);
        //横幅、縦幅
        redLinearLayout.setLayoutParams(new LayoutParams(300, 300));


        //アニメーションを設定
        TranslateAnimation redAnimation =
            new TranslateAnimation(100, 100, 0, 330);//x始点、x終点、y始点、y終点
        //アニメーションする時間 4000ミリ秒 = 4秒間アニメーションする
        redAnimation.setDuration(4000);
        //レイアウトにアニメーションを設定
        redLinearLayout.setAnimation(redAnimation);

     
        //回転するビュー
        TextView blueView = new TextView(this);
        //横幅、縦幅
        blueView.setLayoutParams(new LayoutParams(150, 150));
        //青色に設定
        blueView.setBackgroundColor(Color.BLUE);
        blueView.setText("回転移動");
     
        //開始角度、終了角度、中心点x、中心点y
        RotateAnimation blueAnimation = new RotateAnimation(0, 360, 150, 150);
        //アニメーションする時間 4000ミリ秒 = 4秒間アニメーションする
        blueAnimation.setDuration(4000);
        //ビューにアニメーションを設定
        blueView.setAnimation(blueAnimation);

        //ビューの親子関係を設定。
        //アクティビティに親の緑色レイアウトを設定
        setContentView(greenLinearLayout);
        //緑色レイアウトに子の赤色レイアウトを設定
        greenLinearLayout.addView(redLinearLayout);
        //赤色レイアウトに孫青色ビューを設定
        redLinearLayout.addView(blueView);
    }
}




2012年2月12日日曜日

Squirrelの組み込み Mac編 その2

Squirrelの計算結果をCに渡すのを試します。
Squirrel側では、returnではなくprint()を使って渡します。
他のやり方があって、returnでも渡せるかもしれないが、今回はprint()で渡します。


その1で使った test.nut の中身を下記のように変えます。


function foo(i, f, s)
{
    print(123);
    print(0.987);
    print("abc");
}

その1で使った minimal.c の printfunc 関数の中身を下記のように変えます。


    switch (sq_gettype(v, -2)) {
        case OT_INTEGER:
            SQInteger  ret;
            sq_getinteger(v, -2, &ret);
            sq_pop(v, 1);
            printf(" int = %d ", (int)ret);
            break;
        case OT_FLOAT:
            SQFloat  fret;
            sq_getfloat(v, -2, &fret);
            sq_pop(v, 1);            
            printf(" float = %f ", fret);
            break;
        case OT_STRING:
            const SQChar  *cret;
            sq_getstring(v, -2, &cret);
            sq_pop(v, 1);
            printf(" string = %s ", cret);
            break;    
    }


これで実行してやると

 int = 123  float = 0.987000  string = abc 

と表示されると思います。
Squirrel側でprint()した値がC側に渡されたことになります。

2012年2月11日土曜日

Squirrelの組み込み Mac編 その1

MacでSquirrelを試してみました。

Squirrel 3.0.2 をダウンロード http://squirrel-lang.org/#download
コンパイルして、libフォルダの中にできた libsqstdlib.a と libsquirrel.a を使います。

試すのはSQUIRRELフォルダの中のetcフォルダの中にあるminimal.c と test.nut です。
SQWorkという作業フォルダを作ります。その中にlibフォルダを作り、さっきのライブラリを2つ入れておきます。minimal.c をコンパイルするには、ターミナルで



g++ minimal.c -L/SQWork/lib -lsqstdlib -L/SQWork/lib -lsquirrel -o sample




と入力します。
sampleができあがれば、ターミナルから実行してやると




Called foo(), i=1, f=2.5, s='teststring'




という文字列が表示されると思います。
これでSquirrelの組み込みのHelloWorldは終了です。

2012年1月23日月曜日

デザイン変更

blogのデザインをシンプルなものに変更しました。あと、カテゴリを見れるようにしました。

2011年12月14日水曜日

最近

Javaでxファイルのパーサー制作しているんですが、正直キツい!

2011年11月6日日曜日

Steve Jobs スティーブジョブズの伝記買いました

スティーブ・ジョブズ Ⅰ

スティーブ・ジョブズ Ⅱを買いました。

まだ1冊目を100ページぐらいしか読んでないんですが、ジョブズは小さい頃から特別な子だったようです。
親の影響や、シリコンバレーに住んでいたことなどが影響していて、エレクロニクスに長けた子と知り合うことができたみたいです。

2011年8月17日水曜日

本を2冊買いました。
6年前と11年前に出版された本です。

ーデザインパターンとともに学ぶー オブジェクト指向のこころ

リファクタリング プログラミングの体質改善テクニック

これらを読み終える頃には、ソースを書く意識が変わっていますように。

2011年8月13日土曜日

ノーマルマップ

3Dで凸凹を表現するのにバンプマップとノーマルマップというのがあります。
バンプマップはグレーを基準の色にして、白に近ければ凸に、黒に近ければ凹になるようにレンダリングされます。
ノーマルマップはRGBで凸凹の情報を持たせているので、バンプマップより詳細な凸凹をレンダリングできるということです。

リンク:
WBS+のサイトで紹介されています。
ノーマルマップのBlenderでの作り方がこちらで紹介されています。
○×つくろーどっとコムのサイトで原理が詳しく解説されています。

2011年7月19日火曜日

アクションゲームの当たり判定

アクションゲームの当たり判定を教えてくれと頼まれたので、久しぶりに当たり判定のソースを書いてみました。
C#でXNA用に書いてます。

3段階に分けて書いてみました。
最初は四角と四角の当たり判定。
2つ目は四角と複数の四角の当たり判定。
3つ目はジャンプができる四角と複数の四角の当たり判定。
もっとシンプルにできそうな気もしますが、一応書きたてのものを載せてみました。


四角と四角の当たり判定
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Hit_Test_01
{
    /// 
    /// This is the main type for your game
    /// 
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        Texture2D player;
        Texture2D map;

        Vector2 playerPosition;
        Vector2 mapPosition;

        const int PLAYER_WIDTH = 60;
        const int PLAYER_HEITHT = 90;

        const int MAP_WIDTH = 100;
        const int MAP_HEIGHT = 100;

        KeyboardState keyboardState;
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// 
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// 
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            playerPosition = new Vector2(0, 0);
            mapPosition = new Vector2(100, 100);
            base.Initialize();
        }

        /// 
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// 
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            player = Content.Load("players16");
            map = Content.Load("map");
            // TODO: use this.Content to load your game content here
        }

        /// 
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// 
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// 
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// 
        /// Provides a snapshot of timing values.        protected override void Update(GameTime gameTime)
        {
            keyboardState = Keyboard.GetState();

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            if (keyboardState.IsKeyDown(Keys.Left))
            {
                playerPosition.X -= 1.0f;
                if (Hit())
                {
                    playerPosition.X = mapPosition.X + MAP_WIDTH;
                }
            }
            if (keyboardState.IsKeyDown(Keys.Right))
            {
                playerPosition.X += 1.0f;
                if (Hit())
                {
                    playerPosition.X = mapPosition.X - PLAYER_WIDTH;
                }
            }
            if (keyboardState.IsKeyDown(Keys.Up))
            {
                playerPosition.Y -= 1.0f;
                if (Hit())
                {
                    playerPosition.Y = mapPosition.Y + MAP_HEIGHT;
                }
            }
            if (keyboardState.IsKeyDown(Keys.Down))
            {
                playerPosition.Y += 1.0f;
                if (Hit())
                {
                    playerPosition.Y = mapPosition.Y - PLAYER_HEITHT;
                }
            }

            // TODO: Add your update logic here

            base.Update(gameTime);
        }

        private bool Hit()
        {
            if (playerPosition.X + PLAYER_WIDTH > mapPosition.X &&
                playerPosition.X < mapPosition.X + MAP_WIDTH &&
                playerPosition.Y + PLAYER_HEITHT > mapPosition.Y &&
                playerPosition.Y < mapPosition.Y + MAP_HEIGHT)
            {
                return true;
            }
            return false;
        }
        /// 
        /// This is called when the game should draw itself.
        /// 
        /// Provides a snapshot of timing values.        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            spriteBatch.Begin();
            spriteBatch.Draw(
                map,
                new Rectangle((int)mapPosition.X, (int)mapPosition.Y, MAP_WIDTH, MAP_HEIGHT),
                new Rectangle(0, 0, MAP_WIDTH, MAP_HEIGHT),
                Color.White);
            spriteBatch.Draw(
                player,
                new Rectangle((int)playerPosition.X, (int)playerPosition.Y, PLAYER_WIDTH, PLAYER_HEITHT),
                new Rectangle(0, 0, PLAYER_WIDTH, PLAYER_HEITHT),
                Color.White);
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}



四角と複数の四角の当たり判定。
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Hit_Test_02
{
    /// 
    /// This is the main type for your game
    /// 
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        Texture2D player;
        Texture2D map;

        const int MAP_DIVISION_MAX_X = 8;
        const int MAP_DIVISION_MAX_Y = 5;

        Vector2 playerPosition;
        Vector2 playerSpeed;

        Vector2[,] mapPosition = new Vector2[MAP_DIVISION_MAX_X, MAP_DIVISION_MAX_Y];
        Boolean[,] mapActivity = new Boolean[MAP_DIVISION_MAX_X, MAP_DIVISION_MAX_Y];

        const int PLAYER_WIDTH = 60;
        const int PLAYER_HEITHT = 90;

        const int MAP_WIDTH = 100;
        const int MAP_HEIGHT = 100;

        const int MAP_OFFSET_X = 0;
        const int MAP_OFFSET_Y = 0;

        const float HIT_ADJUST_LENGTH = 1.01f;
        KeyboardState keyboardState;

        enum DIRECTION
        {
            LEFT,
            TOP,
            BOTTOM,
            RIGHT
        }
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// 
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// 
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            playerPosition = new Vector2(MAP_WIDTH * 3, MAP_HEIGHT * 1);
            playerSpeed = new Vector2(0.0f, 0.0f);

            for (int x = 0; x < MAP_DIVISION_MAX_X; ++x)
            {
                for (int y = 0; y < MAP_DIVISION_MAX_Y; ++y)
                {
                    mapPosition[x, y] = new Vector2(x * MAP_WIDTH + MAP_OFFSET_X, y * MAP_HEIGHT + MAP_OFFSET_Y);
                    mapActivity[x, y] = true;
                }
//                mapActivity[x, 0] = false;
            }
            mapActivity[3, 1] = false;
            mapActivity[3, 2] = false;
            mapActivity[4, 1] = false;
            mapActivity[4, 2] = false;

            base.Initialize();
        }

        /// 
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// 
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            player = Content.Load("players16");
            map = Content.Load("map");
            // TODO: use this.Content to load your game content here
        }

        /// 
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// 
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// 
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// 
        /// Provides a snapshot of timing values.        protected override void Update(GameTime gameTime)
        {
            keyboardState = Keyboard.GetState();

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            if (keyboardState.IsKeyDown(Keys.Left))
            {
                playerSpeed.X = -1.0f;
            }
            if (keyboardState.IsKeyDown(Keys.Right))
            {
                playerSpeed.X = 1.0f;
            }
            if (keyboardState.IsKeyDown(Keys.Up))
            {
                playerSpeed.Y = -1.0f;
            }
            if (keyboardState.IsKeyDown(Keys.Down))
            {
                playerSpeed.Y = 1.0f;
            }

            playerPosition += playerSpeed;
            Hit();
            playerSpeed.X = 0.0f;
            playerSpeed.Y = 0.0f;

            // TODO: Add your update logic here

            base.Update(gameTime);
        }

        private void Hit()
        {
            if (playerSpeed.X < 0.0f)
            {
                int x = (int)(playerPosition.X) / MAP_WIDTH;
                int y = (int)(playerPosition.Y + PLAYER_HEITHT - HIT_ADJUST_LENGTH) / MAP_HEIGHT;

                if (mapActivity[x, y] &&
                    playerPosition.X + PLAYER_WIDTH > mapPosition[x, y].X &&
                    playerPosition.X < mapPosition[x, y].X + MAP_WIDTH &&
                    playerPosition.Y + PLAYER_HEITHT > mapPosition[x, y].Y &&
                    playerPosition.Y < mapPosition[x, y].Y + MAP_HEIGHT)
                {
                    playerPosition.X = mapPosition[x, y].X + MAP_WIDTH;
                    playerSpeed.X = 0.0f;
                }
            }
            if (playerSpeed.X > 0.0f)
            {
                int x = (int)(playerPosition.X + PLAYER_WIDTH) / MAP_WIDTH;
                int y = (int)(playerPosition.Y + PLAYER_HEITHT - HIT_ADJUST_LENGTH) / MAP_HEIGHT;

                if (mapActivity[x, y] && 
                    playerPosition.X + PLAYER_WIDTH > mapPosition[x, y].X &&
                    playerPosition.X < mapPosition[x, y].X + MAP_WIDTH &&
                    playerPosition.Y + PLAYER_HEITHT > mapPosition[x, y].Y &&
                    playerPosition.Y < mapPosition[x, y].Y + MAP_HEIGHT)
                {
                    playerPosition.X = mapPosition[x, y].X - PLAYER_WIDTH;
                    playerSpeed.X = 0.0f;
                }
            }
            if (playerSpeed.Y < 0.0f)
            {
                int x = (int)(playerPosition.X) / MAP_WIDTH;
                int y = (int)(playerPosition.Y) / MAP_HEIGHT;

                if (mapActivity[x, y] && 
                    playerPosition.X + PLAYER_WIDTH > mapPosition[x, y].X &&
                    playerPosition.X < mapPosition[x, y].X + MAP_WIDTH &&
                    playerPosition.Y + PLAYER_HEITHT > mapPosition[x, y].Y &&
                    playerPosition.Y < mapPosition[x, y].Y + MAP_HEIGHT)
                {
                    playerPosition.Y = mapPosition[x, y].Y + MAP_HEIGHT;
                    playerSpeed.Y = 0.0f;
                }
            }
            if (playerSpeed.Y > 0.0f)
            {
                int x = (int)(playerPosition.X) / MAP_WIDTH;
                int y = (int)(playerPosition.Y + PLAYER_HEITHT) / MAP_HEIGHT;

                if (mapActivity[x, y] && 
                    playerPosition.X + PLAYER_WIDTH > mapPosition[x, y].X &&
                    playerPosition.X < mapPosition[x, y].X + MAP_WIDTH &&
                    playerPosition.Y + PLAYER_HEITHT > mapPosition[x, y].Y &&
                    playerPosition.Y < mapPosition[x, y].Y + MAP_HEIGHT)
                {
                    playerPosition.Y = mapPosition[x, y].Y - PLAYER_HEITHT;
                    playerSpeed.Y = 0.0f;
                }
            }
        }
        /// 
        /// This is called when the game should draw itself.
        /// 
        /// Provides a snapshot of timing values.        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            spriteBatch.Begin();
            for (int x = 0; x < MAP_DIVISION_MAX_X; ++x)
            {
                for (int y = 0; y < MAP_DIVISION_MAX_Y; ++y)
                {
                    if (mapActivity[x, y])
                    {
                        spriteBatch.Draw(
                            map,
                            new Rectangle((int)mapPosition[x, y].X, (int)mapPosition[x, y].Y, MAP_WIDTH, MAP_HEIGHT),
                            new Rectangle(0, 0, MAP_WIDTH, MAP_HEIGHT),
                            Color.White);
                    }
                }
            }
            spriteBatch.Draw(
                player,
                new Rectangle((int)playerPosition.X, (int)playerPosition.Y, PLAYER_WIDTH, PLAYER_HEITHT),
                new Rectangle(0, 0, PLAYER_WIDTH, PLAYER_HEITHT),
                Color.White);
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}
ジャンプができる四角と複数の四角の当たり判定。
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Hit_Test_03
{
    /// 
    /// This is the main type for your game
    /// 
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        Texture2D player;
        Texture2D map;

        const int MAP_DIVISION_MAX_X = 8;
        const int MAP_DIVISION_MAX_Y = 5;

        Vector2 playerPosition;
        Vector2 playerSpeed;

        const float GRAVITY = 1.0f;

        Vector2[,] mapPosition = new Vector2[MAP_DIVISION_MAX_X, MAP_DIVISION_MAX_Y];
        Boolean[,] mapActivity = new Boolean[MAP_DIVISION_MAX_X, MAP_DIVISION_MAX_Y];

        const int PLAYER_WIDTH = 60;
        const int PLAYER_HEITHT = 90;

        const int MAP_WIDTH = 100;
        const int MAP_HEIGHT = 100;

        const int MAP_OFFSET_X = 0;
        const int MAP_OFFSET_Y = 0;

        const float HIT_ADJUST_LENGTH = 1.01f;
        KeyboardState keyboardState;

        enum DIRECTION
        {
            LEFT,
            TOP,
            BOTTOM,
            RIGHT
        }
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// 
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// 
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            playerPosition = new Vector2(MAP_WIDTH * 3, MAP_HEIGHT * 1);
            playerSpeed = new Vector2(0.0f, 0.0f);

            for (int x = 0; x < MAP_DIVISION_MAX_X; ++x)
            {
                for (int y = 0; y < MAP_DIVISION_MAX_Y; ++y)
                {
                    mapPosition[x, y] = new Vector2(x * MAP_WIDTH + MAP_OFFSET_X, y * MAP_HEIGHT + MAP_OFFSET_Y);
                    mapActivity[x, y] = true;
                }
                //                mapActivity[x, 0] = false;
            }
            mapActivity[2, 1] = false;
            mapActivity[2, 2] = false;
            mapActivity[2, 3] = false;
            mapActivity[3, 1] = false;
           // mapActivity[3, 2] = false;
            mapActivity[3, 3] = false;
            mapActivity[4, 1] = false;
            mapActivity[4, 2] = false;
            mapActivity[4, 3] = false;
            mapActivity[5, 1] = false;
          //  mapActivity[5, 2] = false;
            mapActivity[5, 3] = false;
            mapActivity[6, 1] = false;
            mapActivity[6, 2] = false;
            mapActivity[6, 3] = false;
            base.Initialize();
        }

        /// 
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// 
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            player = Content.Load("players16");
            map = Content.Load("map");
            // TODO: use this.Content to load your game content here
        }

        /// 
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// 
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// 
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// 
        /// Provides a snapshot of timing values.        protected override void Update(GameTime gameTime)
        {
            keyboardState = Keyboard.GetState();

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            if (keyboardState.IsKeyDown(Keys.Left))
            {
                playerSpeed.X = -1.0f;
            }
            if (keyboardState.IsKeyDown(Keys.Right))
            {
                playerSpeed.X = 1.0f;
            }
            if (keyboardState.IsKeyDown(Keys.Up))
            {
                playerSpeed.Y = -10.0f;
            }
            if (keyboardState.IsKeyDown(Keys.Down))
            {
                playerSpeed.Y = 1.0f;
            }

            playerPosition += playerSpeed;
            Hit();
            playerSpeed.X = 0.0f;
            playerSpeed.Y += GRAVITY;

            // TODO: Add your update logic here

            base.Update(gameTime);
        }

        private void Hit()
        {
            if (playerSpeed.X < 0.0f)
            {
                int x = (int)(playerPosition.X) / MAP_WIDTH;
                int y = (int)(playerPosition.Y + PLAYER_HEITHT - HIT_ADJUST_LENGTH - playerSpeed.Y) / MAP_HEIGHT;

                if (mapActivity[x, y] &&
                    playerPosition.X + PLAYER_WIDTH > mapPosition[x, y].X &&
                    playerPosition.X < mapPosition[x, y].X + MAP_WIDTH &&
                    playerPosition.Y + PLAYER_HEITHT > mapPosition[x, y].Y &&
                    playerPosition.Y < mapPosition[x, y].Y + MAP_HEIGHT)
                {
                    playerPosition.X = mapPosition[x, y].X + MAP_WIDTH;
                    playerSpeed.X = 0.0f;
                }
            }
            if (playerSpeed.X > 0.0f)
            {
                int x = (int)(playerPosition.X + PLAYER_WIDTH) / MAP_WIDTH;
                int y = (int)(playerPosition.Y + PLAYER_HEITHT - HIT_ADJUST_LENGTH - playerSpeed.Y) / MAP_HEIGHT;

                if (mapActivity[x, y] &&
                    playerPosition.X + PLAYER_WIDTH > mapPosition[x, y].X &&
                    playerPosition.X < mapPosition[x, y].X + MAP_WIDTH &&
                    playerPosition.Y + PLAYER_HEITHT > mapPosition[x, y].Y &&
                    playerPosition.Y < mapPosition[x, y].Y + MAP_HEIGHT)
                {
                    playerPosition.X = mapPosition[x, y].X - PLAYER_WIDTH;
                    playerSpeed.X = 0.0f;
                }
            }
            if (playerSpeed.Y < 0.0f)
            {
                int x = (int)(playerPosition.X - playerSpeed.X) / MAP_WIDTH;
                int y = (int)(playerPosition.Y) / MAP_HEIGHT;
                if (!mapActivity[x, y] && mapActivity[x + 1, y] && playerPosition.X <= mapPosition[x + 1, y].X)
                {
                    x += 1;
                }
                if (mapActivity[x, y] &&
                    playerPosition.X - HIT_ADJUST_LENGTH + PLAYER_WIDTH > mapPosition[x, y].X &&
                    playerPosition.X - HIT_ADJUST_LENGTH < mapPosition[x, y].X + MAP_WIDTH &&
                    playerPosition.Y + PLAYER_HEITHT > mapPosition[x, y].Y &&
                    playerPosition.Y < mapPosition[x, y].Y + MAP_HEIGHT)
                {
                    playerPosition.Y = mapPosition[x, y].Y + MAP_HEIGHT;
                    playerSpeed.Y = 0.0f;
                }
            }
            if (playerSpeed.Y > 0.0f)
            {
                int x = (int)(playerPosition.X) / MAP_WIDTH;
                int y = (int)(playerPosition.Y + PLAYER_HEITHT) / MAP_HEIGHT;
                if (!mapActivity[x, y] && mapActivity[x + 1, y] && playerPosition.X <= mapPosition[x + 1, y].X)
                {
                    x += 1;
                }
                if (mapActivity[x, y] &&
                    playerPosition.X + PLAYER_WIDTH > mapPosition[x, y].X &&
                    playerPosition.X < mapPosition[x, y].X + MAP_WIDTH &&
                    playerPosition.Y + PLAYER_HEITHT > mapPosition[x, y].Y &&
                    playerPosition.Y < mapPosition[x, y].Y + MAP_HEIGHT)
                {
                    playerPosition.Y = mapPosition[x, y].Y - PLAYER_HEITHT;
                    playerSpeed.Y = 0.0f;
                }
            }
        }
        /// 
        /// This is called when the game should draw itself.
        /// 
        /// Provides a snapshot of timing values.        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            spriteBatch.Begin();
            for (int x = 0; x < MAP_DIVISION_MAX_X; ++x)
            {
                for (int y = 0; y < MAP_DIVISION_MAX_Y; ++y)
                {
                    if (mapActivity[x, y])
                    {
                        spriteBatch.Draw(
                            map,
                            new Rectangle((int)mapPosition[x, y].X, (int)mapPosition[x, y].Y, MAP_WIDTH, MAP_HEIGHT),
                            new Rectangle(0, 0, MAP_WIDTH, MAP_HEIGHT),
                            Color.White);
                    }
                }
            }
            spriteBatch.Draw(
                player,
                new Rectangle((int)playerPosition.X, (int)playerPosition.Y, PLAYER_WIDTH, PLAYER_HEITHT),
                new Rectangle(0, 0, PLAYER_WIDTH, PLAYER_HEITHT),
                Color.White);
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}

2011年6月17日金曜日

PSVita

PSVitaの開発環境はどうなるんだろう?
開発機材があるのかな。もしPSVita実機だけでデバッグできたら、個人の開発者が増えるんではなかろうか。
統合開発環境とかもeclipseとかが使えたら、ぐっと開発者が増えると思う。
SCEにできるだけオープンな開発環境を整えてもらいたいと願ってます。

2011年5月18日水曜日

OpenGLES入門 その3 テクスチャの表示

今回はテクスチャを表示させます。
今回は表示させる画像にこのimage.pngを使用します。


そしてOpenGL入門その2で使用したソースコードを流用します。

MyApplication.javaはそのままで、Renderer.javaとScene.javaの中身を少し変更します。

■Renderer.java■
package test.sample;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.view.Display;

public class GLRenderer implements GLSurfaceView.Renderer {

 private Scene mScene;
 private boolean mOnce = true;
 private Activity mActivity;
 public GLRenderer(Activity activity, Display display) {
  mScene = new Scene(display);
  mActivity = activity;
 }

 @Override
 public void onDrawFrame(GL10 gl) {//毎フレーム呼ばれるメインループ

  if (mOnce) {
   mScene.setTexture(gl, mActivity.getResources().openRawResource(R.drawable.image));
   mOnce = false;
  }
  mScene.draw(gl);
 }

 @Override
 public void onSurfaceChanged(GL10 arg0, int arg1, int arg2) {
 }

 @Override
 public void onSurfaceCreated(GL10 gl, EGLConfig config) {
 }
}

■Scene.java■
package test.sample;

import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import javax.microedition.khronos.opengles.GL10;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLU;
import android.opengl.GLUtils;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;

public class Scene implements View.OnTouchListener{

 private FloatBuffer vertexBuffer;
 private FloatBuffer textureBuffer;


 private int mTextureNumber;
 private int mWidth;
 private int mHeight;

 public Scene(Display display) {
  mWidth = display.getWidth();
  mHeight = display.getHeight();

  float x = 0.0f;
  float y = 0.0f;
  float z = 0.0f;
  float sizeX = 10.0f;
  float sizeY = 10.0f;
  float sizeZ = 0.0f;
  float[] vertex = {
    //左側の三角形
    x + sizeX, y + sizeY, z + sizeZ,//右下
    x - sizeX, y - sizeY, z + sizeZ,//左上
    x - sizeX, y + sizeY, z + sizeZ,//左下
    //右側の三角形
    x + sizeX, y + sizeY, z + sizeZ,//右下
    x + sizeX, y - sizeY, z + sizeZ,//右上
    x - sizeX, y - sizeY, z + sizeZ,//左上
  };
  ByteBuffer vb = ByteBuffer.allocateDirect(6 * 3 * 4);
  vb.order(ByteOrder.nativeOrder()); //ビッグエンディアンかリトルエンディアンにあわせてくれる
  vertexBuffer = vb.asFloatBuffer();
  vertexBuffer.put(vertex);
  vertexBuffer.position(0);

  float[] texture = {
    1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, //左側の三角形に貼る
    1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f //右側の三角形に貼る
  };
  ByteBuffer tb = ByteBuffer.allocateDirect(2 * 3 * 2 * 4);
  tb.order(ByteOrder.nativeOrder()); //ビッグエンディアンかリトルエンディアンにあわせてくれる
  textureBuffer = tb.asFloatBuffer();
  textureBuffer.put(texture);
  textureBuffer.position(0);

 }


    public void setTexture(GL10 gl, InputStream is)
    {
     Bitmap bitmap;
     try {
      bitmap = BitmapFactory.decodeStream(is);
     } finally {
      try {
       is.close();
      } catch(IOException e) {}
     }
     int[] textureNumber = new int[1];
     gl.glGenTextures(1, textureNumber, 0);
     mTextureNumber = textureNumber[0];
     gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureNumber);
     GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

     gl.glTexParameterx( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT );
     gl.glTexParameterx( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT );
     gl.glTexParameterx( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR );
     gl.glTexParameterx( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR );

    }

 public void draw(GL10 gl) {
  gl.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);

     gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

  //ビューポート行列(ウィンドウへの出力領域)設定
  gl.glViewport(0,0,mWidth,mHeight);

  //射影行列設定
  gl.glMatrixMode(GL10.GL_PROJECTION);
  gl.glLoadIdentity();
  //視界(視野角、画面のアスペクト、比近視点、遠視点)の設定
  float aspect = (float)mWidth / (float)mHeight;
  GLU.gluPerspective(gl, 45.0f, aspect, 0.1f, 3000.0f);

     GLU.gluLookAt(
              gl,
        0.0f, 0.0f, 100.0f,  //位置(視点)
       0.0f, 0.0f, 0.0f,  //見つめているところ
       0.0f, 1.0f, 0.0f //水平
     );
     gl.glMatrixMode(GL10.GL_MODELVIEW);
     gl.glLoadIdentity();

  gl.glEnable(GL10.GL_TEXTURE_2D);
  gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
  gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

  gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
  gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);

  int triangleNum = 2;
  gl.glDrawArrays(GL10.GL_TRIANGLES, 0, triangleNum * 3);
 }

 @Override
 public boolean onTouch(View arg0, MotionEvent arg1) {
  // TODO 自動生成されたメソッド・スタブ
  return false;
 }

}


画像をdrawable-hdpiに登録してから実行すると下のように表示されます。






2011年3月28日月曜日

OpenGLES入門 その2

今回は三角ポリゴンを2枚表示させます。
下のような青と緑のポリゴンが表示できると思います。

■MyApplication.java■

import android.app.Activity; import android.opengl.GLSurfaceView; import android.os.Bundle; import android.view.WindowManager; 
public class MyApplication extends Activity {
private GLSurfaceView mGLSurfaceView; private GLRenderer mGLRenderer; @Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); mGLSurfaceView = new GLSurfaceView(this); setContentView(mGLSurfaceView); WindowManager windowmanager = (WindowManager)getSystemService(WINDOW_SERVICE); mGLRenderer = new GLRenderer(this, windowmanager.getDefaultDisplay()); mGLSurfaceView.setRenderer(mGLRenderer);
}
/** * */ public void onPause() {
mGLSurfaceView.onPause(); super.onPause();
}
/** * */ public void onResume() {
super.onResume(); mGLSurfaceView.onResume();
}
}


 ■GLRenderer.java■

import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import android.app.Activity; import android.opengl.GLSurfaceView; import android.opengl.GLU; import android.view.Display; 
public class GLRenderer implements GLSurfaceView.Renderer { private Scene mScene; public GLRenderer(Activity activity, Display display) { mScene = new Scene(display); } @Override public void onDrawFrame(GL10 gl) {//毎フレーム呼ばれるメインループ mScene.draw(gl); } @Override public void onSurfaceChanged(GL10 arg0, int arg1, int arg2) { } @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { } }
 ■Scene.java■

import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import javax.microedition.khronos.opengles.GL10; import android.opengl.GLU; import android.view.Display; import android.view.MotionEvent; import android.view.View; public class Scene implements View.OnTouchListener{ private FloatBuffer vertexBuffer; private FloatBuffer colorBuffer; private int mWidth; private int mHeight; public Scene(Display display) { mWidth = display.getWidth(); mHeight = display.getHeight(); float x = 0.0f; float y = 0.0f; float z = 0.0f; float sizeX = 10.0f; float sizeY = 10.0f; float sizeZ = 0.0f; float[] vertex = { //左側の三角形 x + sizeX, y - sizeY, z + sizeZ, x - sizeX, y - sizeY, z + sizeZ, x - sizeX, y + sizeY, z + sizeZ, //右側の三角形 x - sizeX, y + sizeY, z + sizeZ, x + sizeX, y + sizeY, z + sizeZ, x + sizeX, y - sizeY, z + sizeZ, }; ByteBuffer vb = ByteBuffer.allocateDirect(6 * 3 * 4); vb.order(ByteOrder.nativeOrder()); //ビッグエンディアンかリトルエンディアンにあわせてくれる vertexBuffer = vb.asFloatBuffer(); vertexBuffer.put(vertex); vertexBuffer.position(0); float[] color = { //左側の三角形(青) 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, //右側の三角形(緑) 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f }; ByteBuffer vbc = ByteBuffer.allocateDirect(6 * 4 * 4); vbc.order(ByteOrder.nativeOrder()); //ビッグエンディアンかリトルエンディアンにあわせてくれる colorBuffer = vbc.asFloatBuffer(); colorBuffer.put(color); colorBuffer.position(0); } public void draw(GL10 gl) { gl.glClearColor(1.0f, 0.0f, 0.0f, 1.0f); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
//ビューポート行列(ウィンドウへの出力領域)設定 gl.glViewport(0,0,mWidth,mHeight); //射影行列設定 gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); //視界(視野角、画面のアスペクト、比近視点、遠視点)の設定 float aspect = (float)mWidth / (float)mHeight; GLU.gluPerspective(gl, 45.0f, aspect, 0.1f, 3000.0f); GLU.gluLookAt(
            gl,       0.0f, 0.0f, 100.0f, //位置(視点)     0.0f, 0.0f, 0.0f, //見つめているところ            0.0f, 1.0f, 0.0f //水平 );
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_COLOR_ARRAY); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); gl.glColorPointer(4, GL10.GL_FLOAT, 0, colorBuffer); int triangleNum = 2; gl.glDrawArrays(GL10.GL_TRIANGLES, 0, triangleNum * 3); } @Override public boolean onTouch(View arg0, MotionEvent arg1) { return false; } }



PR » 看板
PR » 名刺 作成

2011年3月23日水曜日

Androidアプリ公開

「ポリゴンワールド」をマーケットに公開しました。
無料です。
https://market.android.com/developer?pub=minmin0530

初めて作ったAndroidアプリです。
Android持ってる方は是非ダウンロードしてみて下さい。








2011年3月1日火曜日

OpenGLES入門 その1

AndroidでのOpenGLESの使い方をおおまかに書いておきます。

■1
MyApplicationを作る。まずActivityを継承する

class MyApplication extends Activity {
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //AbsoluteLayoutを使うのは、後でボタンやテキストを表示させるため。
    AbsoluteLayout layout=new AbsoluteLayout(this);
    setContentView(layout);

    //GLサーフェイスビューを生成して設定
    GLSurfaceView mGLSurfaceView = new GLSurfaceView(this);
    GLRenderer glRenderer = new GLRenderer(this);
    mGLSurfaceView.setRenderer(glRenderer);
    layout.addView(mGLSurfaceView);
  }
}

■2
GLRendererクラスはGLSurfaceView.Rendererを継承する

public class GLRenderer implements GLSurfaceView.Renderer {
  private Scene mScene;
  private Resources mResource;

  public GLRenderer(Activity activity) {
    mResource = activity.getResources();//これは後でテクスチャを読み込むときに使う。
    mScene = new Scene();
  }

  //このonDrawFrameメソッドが毎フレーム呼ばれるので、ここで描画処理、更新処理を行う。
  public void onDrawFrame(GL10 gl) {
    mScene.draw(gl);
    mScene.update();
  }

  public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    //ここにOpenGLの初期化処理を書いておく
  }
}

■3
SceneクラスはView.OnTouchListenerを継承する

public class Scene implements View.OnTouchListener{
  public void draw(GL10 gl) {
    //ここにポリゴンの描画処理を書く
  }
  public void update() {
    //ここに物体の移動処理などを書く
  }
  public boolean onTouch(View v, MotionEvent event) {
    //ここにタッチ操作処理を書く
    return false;
  }
}

これをコピペしても動きません。すみません。
これで大体の流れをつかんで下さい。