基础对象如何在Panda3d中控制相机

时间:2019-01-23 07:17:07

标签: python panda3d

我想在Panda3d引擎中创建自定义几何。接下来的代码可以100%正确地工作。

   public class RestfulServiceMgr
{
    public string EndPoint { get; set; }
    public HttpVerb Method { get; set; }
    public string ContentType { get; set; }
    public string PostData { get; set; }

    public RestfulServiceMgr()
    {
        EndPoint = "";
        Method = HttpVerb.GET;
        ContentType = "application/json";
        PostData = "";
    }
    public RestfulServiceMgr(string endpoint)
    {
        EndPoint = endpoint;
        Method = HttpVerb.GET;
        ContentType = "application/json";
        PostData = "";
    }
    public RestfulServiceMgr(string endpoint, HttpVerb method)
    {
        EndPoint = endpoint;
        Method = method;
        ContentType = "application/json";
        PostData = "";
    }

    public RestfulServiceMgr(string endpoint, HttpVerb method, string postData)
    {
        EndPoint = endpoint;
        Method = method;
        ContentType = "application/json";
        PostData = postData;
    }

    public string MakeRequest()
    {
        return MakeRequest("");
    }

    public string MakeRequest(string parameters)
    {
        var request = (HttpWebRequest)WebRequest.Create(EndPoint + parameters);

        request.Method = Method.ToString();
        request.ContentLength = 0;
        request.ContentType = ContentType;

        if (!string.IsNullOrEmpty(PostData) && Method == HttpVerb.POST)
        {
            var encoding = new UTF8Encoding();
            var bytes = Encoding.GetEncoding("iso-8859-1").GetBytes(PostData);
            request.ContentLength = bytes.Length;

            using (var writeStream = request.GetRequestStream())
            {
                writeStream.Write(bytes, 0, bytes.Length);
            }
        }

        using (var response = (HttpWebResponse)request.GetResponse())
        {
            var responseValue = string.Empty;

            if (response.StatusCode != HttpStatusCode.OK)
            {
                var message = String.Format("Request failed. Received HTTP {0}", response.StatusCode);
                throw new ApplicationException(message);
            }

            // grab the response
            using (var responseStream = response.GetResponseStream())
            {
                if (responseStream != null)
                    using (var reader = new StreamReader(responseStream))
                    {
                        responseValue = reader.ReadToEnd();
                    }
            }

            return responseValue;
        }
    }
}

当我从代码中删除class FooBarTriangle(ShowBase): def __init__(self): super(self).__init__() self.disable_mouse() self.set_frame_rate_meter(True) self.accept("escape", sys.exit) self.accept("space", lambda: print(self.camera.get_pos())) self.camera.set_pos(0, 0, 10) self.camera.look_at(0, 0, 0) self._add_light() self._add_triangle() def _add_light(self): # Adds a point light pass def _add_triangle(self): # Adds a single triangle in a certain place pass 时,就会发生神秘的事情。我希望我的相机可以移动并出现在(0,0,10)位置,看着(0,0,0)。但是,相反,摄影机位于(0,0,0)的位置,我不知道它在哪里。

为什么会发生?

1 个答案:

答案 0 :(得分:3)

之所以会发生这种情况,是因为Panda3D具有默认的摄像头控件(默认的摄像头驱动程序),如果您不调用camera.set_pos(x, y, z),Panda3D将不会通过调用来移动摄像头(0, 0, 0),但仅允许通过指定的控件进行移动,如手册中的herehere所示。

如果您希望能够通过代码将相机放置到{{1}}以外的任何位置,则必须编写自己的相机控制器,或者仅使用上面链接上指示的控件在场景中移动。

>