10
  • using PhoenGap 2.2.0
  • Executed \bin\create C:\Temp\Test com.test Test
  • Had following output

Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved.

Creating new android project...
Building jar and js files...
Copying template files...
Copying js, jar & config.xml files...
Copying cordova command tools...
Updating AndroidManifest.xml and Main Activity...
  • Imported Project
    • On eclipse (4.2.0) did
    • File > New > Project > Android > Android Project from Existing Code
    • Selected the folder C:\Temp\Test
    • Checked "Copy project into workspace"
  • Making changes
    • Checked res\xml\config.xml and the line <plugin name="Notification" value="org.apache.cordova.Notification"/> is present
    • Checked that index.html has the cordova-2.2.0.js included
    • Case#1 Opened index.html and modified from

<script type="text/javascript"> app.initialize(); </script>

to

<script type="text/javascript">
function showAlert(msg){
navigator.notification.alert(msg);
}
document.addEventListener("deviceready", showAlert('You are the winner!'), false);
app.initialize();
</script>

I get following error 11-25 10:29:58.399: E/Web Console(14604): Uncaught TypeError: Cannot call method 'alert' of undefined at file:///android_asset/www/index.html:40

    • Case#2 Opened index.html and modified from

<script type="text/javascript"> app.initialize(); </script>

to

<script type="text/javascript">
function successAlert(){}
function errorAlert(){}
function showAlert(msg){
cordova.exec(successAlert, errorAlert, "Notification","alert", [msg]);
}
document.addEventListener("deviceready", showAlert('You are the winner!'), false);
app.initialize();
</script>

I get following error 11-25 10:25:06.575: E/Web Console(14149): Uncaught TypeError: Object #<Object> has no method 'exec' at file:///android_asset/www/index.html:42 }

I'm sure that I missed something...just that I'm not able to conclude what is it. Please help me out.


calculation for ray generation in ray tracer

I am implementing a basic ray tracer so I am reading up on theory and other implementations. Here is the code that I am currently referring to

    template<typename T>
void render(const std::vector<Sphere<T> *> &spheres)
{
    int width = 800, height = 800;//define width and height of the screen
    Vector3d<T> *image = new Vector3d<T>[width * height], *pixel = image;
    T invWidth = 1 / T(width), invHeight = 1 / T(height);
    T fov = 90, aspectratio = width / T(height);//defining field of view angle and aspect ratio
    T fovDist = tan(M_PI * 0.5 * fov / T(180));//Calculates half screen width / perpendicular distance to the camer
a position
    // For each ray crossing a pixel on the view screen.
    for (int y = 0; y < height; ++y) //For each scan line
    {
        for (int x = 0; x < width; ++x, ++pixel) //for each pixel on a scan line
        {
            //Calculate the x position using centre of the pixel. 
           /*By simple trig (width/2)/perpendicular distance to camera = tan (fov/2)
             =>width = distance * tan (fov/2)

           */
            T xx = (2 * ((x + 0.5) * invWidth) - 1) * fovDist * aspectratio;
            T yy = (1 - 2 * ((y + 0.5) * invHeight)) * fovDist;//Calculate the y position
            Vector3d<T> raydir(xx, yy, -1);
            raydir.normalize();
            *pixel = trace(Vector3d<T>(0), raydir, spheres, 0);
        }
    }

I am putting in comments of what I understand but I am stuck on the calculation of xx and yy.

I understand that by simple trigonometry width = 2 * (perpendicular distance from camera to the view plane) * tan (fov / 2). But I am not able to figure out the expression for T xx and T yy.

Please can someone help clarify.

Regards, Moira

4

1 に答える 1

11

showAlertこれは、イベントが発生するまで遅らせるのではなく、すぐに呼び出します。

document.addEventListener("deviceready", showAlert('You are the winner!'), false)

代わりにこれを行う

document.addEventListener("deviceready", function() {
    showAlert('You are the winner!')
}, false)
于 2012-11-25T22:43:52.553 に答える