2013-10-01 4 views
5

मैं एंड्रॉइड विकास के लिए काफी नया हूं, मुझे मूलभूत गतिविधियां, मानचित्र, स्क्लाइट इत्यादि पता है मैं कुछ 3 डी ऑब्जेक्ट्स को लागू करने में सक्षम होना चाहता हूं मेरे ऐप्स के साथ बातचीत करने में सक्षम। थोड़ी सी खोज के बाद मैंने पाया कि राजवाली सबसे अच्छी विधि प्रतीत होती है। जैसा कि आप करते हैं मैंने पहले ट्यूटोरियल के साथ शुरुआत की और उदाहरण दस्तावेज़ों से स्रोत कोड पढ़ना शुरू किया। जहां मैं खो गया हूं, मैंने शब्द के लिए ट्यूटोरियल शब्द का पालन किया है और मैं स्क्रिप्ट में त्रुटियों के कारण एप्लिकेशन को चला नहीं सकता। अगर किसी ने राजवाली का इस्तेमाल किया है, तो इससे पहले कि मैं कुछ पॉइंटर्स को समझूंगा कि मैं कहां गलत हूं। (ट्यूटोरियल अंतिम बार 2 महीने पहले अपडेट किया गया था, इसलिए यह काफी हालिया है)। Tutorialआप काम करने के लिए राजवाली कैसे प्राप्त करते हैं (गिट पर ट्यूटोरियल 1)

यहाँ मेरी स्रोत कोड

MainActivity है:

package rajawali.tutorials; 

import rajawali.RajawaliActivity; 
import android.os.Bundle; 
import android.view.Menu; 

public class MainActivity extends RajawaliActivity { 
    private Renderer mRenderer; 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     mRenderer = new Renderer(this); 
     mRenderer.setSurfaceView(mSurfaceView); 
     super.setRenderer(mRenderer); 
    } 
} 

प्रतिपादक:

package rajawali.tutorials; 

import javax.microedition.khronos.opengles.GL10; 

import android.content.Context; 
import rajawali.lights.DirectionalLight; 
import rajawali.materials.textures.ATexture.TextureException; 
import rajawali.materials.textures.Texture; 
import rajawali.primitives.Sphere; 
import rajawali.renderer.RajawaliRenderer; 

public class Renderer extends RajawaliRenderer { 

    private DirectionalLight mLight; 
    Sphere mSphere; 

    public Renderer(Context context) { 
     super(context); 
     setFrameRate(60); 
    } 
    public void initScene() { 
     mLight = new DirectionalLight(1f, 0.2f, -1.0f); 
     mLight.setColor(1.0f, 1.0f, 1.0f); 
     mLight.setPower(2); 

     try { 
      *DiffuseMaterial* material = new *DiffuseMaterial*(); //there is an error here (DiffuseMaterial cannot be rsolved as a type) 
      material.addTexture(new *Texture(R.drawable.earthtruecolor_nasa_big)*); //here (constructor Texture(int) cannot be defined) 
      mSphere = new Sphere(1, 24, 24); 
      mSphere.setMaterial(material); 
      mSphere.*addLight(mLight)*; //and here (The method addLight(DirectionalLight) is undefined for the type Sphere) 
      addChild(mSphere); 
     } catch (TextureException e) { 
      e.printStackTrace(); 
     } 
     getCurrentCamera().setZ(4.2f); 
    } 

    @Override 
    public void onDrawFrame(GL10 glUnused) { 
     super.onDrawFrame(glUnused); 
     mSphere.setRotY(mSphere.getRotY() + 1); 
    } 

} 

मैं नहीं है वास्तव में अगर मैं इसे मदद कर सकते हैं चम्मच फ़ीड कोड होना चाहता हूँ, लेकिन यह ऐसा लगता है कि त्रुटि 'डिफ्यूजमटेरियल' में है। मिनी 3 डी या राजवाली का उपयोग करने के अलावा 3 डी ऑब्जेक्ट्स में हेरफेर करने का यह बेहतर तरीका क्यों है?

उत्तर

7

मैं भी अगले कोड का उपयोग करके इस राजवाली ट्यूटोरियल को चलाने की कोशिश कर रहा हूं।

कक्षा RajawaliTutorialActivity

package rajawali.tutorials; 

import rajawali.RajawaliActivity; 
import android.os.Bundle; 

public class RajawaliTutorialActivity extends RajawaliActivity { 

    public RajawaliTutorialRenderer mRenderer; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     mRenderer = new RajawaliTutorialRenderer(this); 
     mRenderer.setSurfaceView(mSurfaceView); 
     super.setRenderer(mRenderer); 
    } 
} 



कक्षा RajawaliTutorialRenderer

package rajawali.tutorials; 

import javax.microedition.khronos.opengles.GL10; 

import android.content.Context; 

import rajawali.Camera; 
import rajawali.Object3D; 
import rajawali.lights.DirectionalLight; 
import rajawali.materials.Material; 
import rajawali.materials.textures.ATexture.TextureException; 
import rajawali.materials.textures.Texture; 
import rajawali.primitives.Sphere; 
import rajawali.renderer.RajawaliRenderer; 

public class RajawaliTutorialRenderer extends RajawaliRenderer { 

    public DirectionalLight light; 
    public Object3D sphere; 
    public Context context; 
    public Camera camera; 

    public RajawaliTutorialRenderer(Context context) { 
     super(context); 
     this.context = context; 
     setFrameRate(60); 
    } 

    public void initScene() { 
     light = new DirectionalLight(1f, 0.2f, -1.0f); // set the direction 
     light.setColor(1.0f, 1.0f, 1.0f); 
     light.setPower(2); 

     try{ 
      Material material = new Material(); 
      material.addTexture(new Texture("earthColors", R.drawable.earthtruecolor_nasa_big)); 
      material.setColorInfluence(0); 
      sphere = new Sphere(1, 24, 24); 
      sphere.setMaterial(material); 
      getCurrentScene().addLight(light); 
      super.addChild(sphere); 
     } catch (TextureException e){ 
      e.printStackTrace(); 
     } 

     getCurrentCamera().setZ(4.2f); 
    } 

    @Override 
    public void onDrawFrame(GL10 glUnused) { 
     super.onDrawFrame(glUnused); 
     sphere.setRotY(sphere.getRotY() + 1); 
    } 
} 

देखें कि परिवर्तन कर रहे हैं:

  1. sphere ऑब्जेक्ट Object3D के बजाय Sphere घोषित करें।
  2. DiffuseMaterialMaterial द्वारा सामग्री घोषणा के लिए बदलें।
  3. Texture प्राप्त करने के लिए पैरामीटर बदलें। पहला पैरामीटर एक कस्टम पहचानकर्ता है और दूसरा पैरामीटर संसाधन आईडी है।
  4. लोड बनावट के बाद material.setColorInfluence(0); लाइन जोड़ें, यदि यह पंक्ति नहीं जोड़ा गया है, तो "दिल" लाल हो जाता है (मुझे यकीन नहीं है क्यों)।
  5. addLight विधि पर कॉल करने के लिए दृश्य वस्तु (getCurrentScene विधि के साथ पहुंच) द्वारा sphere ऑब्जेक्ट को प्रतिस्थापित करें। इस विधि के रूप में लाइन material.addTexture() के लिए
  6. जोड़ें ट्राई/कैच अब एक TextureException
  7. initScene
+0

यह शानदार है। मुझे आश्चर्य है कि ट्यूटोरियल क्यों काम नहीं करता है। क्या इस तरह के बाकी ट्यूटोरियल हैं? –

+0

यकीन नहीं है, मैंने एक और ट्यूटोरियल करने की कोशिश नहीं की, लेकिन ऐसा लगता है कि ट्यूटोरियल राजवाली के पिछले संस्करण के लिए बनाया गया था। – doanvelagui

+2

super.addChild अब काम नहीं कर रहा है। 'getCurrentScene()। addChild' काम करता है। – nunespascal

2

के अंत ऐसा लगता है कि इस Rajawali के संस्करण के साथ क्या करना है की तरह करने के लिए getCurrentCamera().setZ(4.2f); जोड़ने फेंकता है।

चाहे आप क्लोन या डाउनलोड करने के लिए चुनते हैं, तो आप शायद रिलीज टैग में से एक का उपयोग करना चाहते जाएगा:

this page पर यह master शाखा उपयोग करने के लिए नहीं कहते हैं। पुस्तकालय और उदाहरण दोनों की मास्टर शाखा विकास के लिए उपयोग की जाती है और इसे उत्पादन कोड के लिए अस्थिर माना जाना चाहिए। जब हम एक स्थिर संस्करण जारी करते हैं, तो इसे टैग किया जाएगा। यदि आप क्लोनिंग कर रहे हैं, तो आप बस एक टैग चेकआउट कर सकते हैं।

आप git का उपयोग कर Rajawali क्लोन हैं, तो आप एक टैग से चेकआउट करने के लिए चाहता हूँ। टैग को सूचीबद्ध करने के:

$ git tag 
v0.9 

लेखन के समय, v0.9 अपने ही विकल्प है।

$ git checkout v0.9 

अब आपके पास DiffuseMaterial उपलब्ध होगा। हालांकि, कुछ अन्य वर्ग अभी भी गायब हैं।

संपादित करें:

यह इस ट्यूटोरियल की तरह दिखता है न v0.9 है और न ही नवीनतम मास्टर शाखा पर लागू होता है। मैंने ट्यूटोरियल 1 का एक वर्किंग वर्जन बनाया, जो you can find linked here है।

1

आप मास्टर शाखा का उपयोग करने के प्रदर्शन के रूप में योगदान किए गए उदाहरणों से बना राजवालीएक्समल्स एप्लिकेशन का भी उपयोग कर सकते हैं।

https://github.com/MasDennis/RajawaliExamples

इसके अलावा डीन पर स्पष्ट करने के लिए बोली, बयान है से डर लग रहा है जब एपीआई उन्हें नीचे बदल जो ज्यादातर प्रासंगिक था जब jwoolston बड़े परिवर्तन दृश्य रेखांकन समर्थन करने के लिए कर रहा था से लोगों को रोकने के बनाया है। उस काम का बड़ा हिस्सा किया जाता है और यदि कभी खत्म हो जाता है, तो एपीआई अपने वर्तमान राज्य से महत्वपूर्ण रूप से बदल सकता है क्योंकि अन्य प्रमुख वस्तुएं पहले ही पूरी हो चुकी हैं। इस तरह के आइटम एनीमेशन, अधिक पार्सिंग विकल्प, लचीली प्रतिपादन इत्यादि जैसे टुकड़े हैं

संबंधित मुद्दे

 संबंधित मुद्दे