如何在不使用gluUnProject的情况下将屏幕坐标转换为现代OpenGL中的世界坐标?
我有Group由其他Group对象组成的对象,最终由Actor对象组成.现在,当旋转,偏移和缩放组和角色时,"世界"中的坐标或与根节点相关的坐标会发生变化.如何获取演员当地空间中某个点的世界坐标?
为了说明一点,这是我想要的一个例子:
Group parentGroup;
Actor childInGroup;
...
parentGroup.addActor(childInGroup);
childInGroup.setPosition(10f, 15f);
childInGroup.setRotation(45f);
// Get the childInGroup's position in the world
float childWorldPosX = ...; // This is what I want to know
float childWorldPosY = ...; // ... and this.
Run Code Online (Sandbox Code Playgroud) 我有一个每周统计系统,我想检查统计数据最后一次更新是否是上周.如果是的话,我想清除它.
目前,日期存储在LocalDate:
LocalDate lastUpdate;
Run Code Online (Sandbox Code Playgroud)
我已经有了这样的日常统计数据:
if(lastUpdate.isBefore(LocalDate.now())
{
clearDailyStatistics();
}
Run Code Online (Sandbox Code Playgroud)
我想做这样的事情:
if(/* something here? */)
{
clearWeeklyStatistics();
}
Run Code Online (Sandbox Code Playgroud)
所以,问题是:我如何比较LocalDate对象的周数?不需要形成周的不同"标准" - 周一到周日将被使用(如Java DayOfWeek课程已经使用的那样).
我有多个共享一个公共基类的类,如下所示:
class Base {};
class DerivedA : public Base {};
class DerivedB : public Base {};
class DerivedC : public Base {};
Run Code Online (Sandbox Code Playgroud)
现在,我需要知道在运行时(基于输入)实例化这些派生类中的哪一个.例如,如果是输入"DerivedA",我需要创建一个DerivedA对象.输入不一定是字符串,也可以是整数 - 关键是有某种键,我需要一个值来匹配键.
但问题是,如何实例化该类?C++没有像C#或Java那样的内置反射.我发现一个常见的解决方案是使用这样的工厂方法:
Base* create(const std::string& name) {
if(name == "DerivedA") return new DerivedA();
if(name == "DerivedB") return new DerivedB();
if(name == "DerivedC") return new DerivedC();
}
Run Code Online (Sandbox Code Playgroud)
如果只有几个类,这就足够了,但如果有几十个或几百个派生类,那就变得很麻烦并且可能很慢.我可以很容易地自动化地图创建过程来生成一个std::map<std::string, ***>,但我不知道要存储什么作为值.AFAIK,不允许指向构造函数的指针.同样,如果我使用这个地图做工厂,我仍然需要为每种类型编写一个工厂方法,使其比上面的例子更麻烦.
什么是处理这个问题的有效方法,特别是当有很多派生类时?
我需要将一堆文件(大约40-50)还原到特定的提交.但是,我不想还原所有文件.如果不为每个需要还原的文件执行每个文件签出,我该怎么做?我需要还原的所有文件都位于一个文件夹下.
我有一个使用 Django REST Framework 和 Django-allauth 的 Django 应用程序。现在,我正在尝试检索社交帐户中存在的头像 URL。但是,我在形成序列化器时遇到问题。
对于背景信息,allauthsSocialAccount通过外键与用户模型相关:
class SocialAccount(models.Model):
user = models.ForeignKey(allauth.app_settings.USER_MODEL)
# the method I'm interested of
def get_avatar_url(self):
...
Run Code Online (Sandbox Code Playgroud)
现在,这是我目前拥有的序列化器:
class ProfileInfoSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id', 'first_name', 'last_name')
Run Code Online (Sandbox Code Playgroud)
最后,我想要一个额外的字段来avatar_url获取模型中方法调用的结果SocialAccount。我怎么做?
我有一个Android客户端应用程序尝试使用Django + DRF后端进行身份验证.但是,当我尝试登录时,我得到以下响应:
403: CSRF Failed: CSRF token missing or incorrect.
Run Code Online (Sandbox Code Playgroud)
该请求将发送给http://localhost/rest-auth/google/以下机构:
access_token: <the OAuth token from Google>
Run Code Online (Sandbox Code Playgroud)
什么可能导致这个?客户端没有CSRF令牌,因为要进行身份验证的POST是客户端和服务器之间首先发生的事情.我检查了很多过去的问题同样的问题,但我找不到任何解决方案.
Django方面的相关设置如下:
AUTHENTICATION_BACKENDS = (
"django.contrib.auth.backends.ModelBackend",
"allauth.account.auth_backends.AuthenticationBackend"
)
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.request",
"django.contrib.auth.context_processors.auth",
"allauth.account.context_processors.account",
"allauth.socialaccount.context_processors.socialaccount"
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'app',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.google',
'django.contrib.admin',
# REST framework
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'rest_auth.registration',
)
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated'
),
}
Run Code Online (Sandbox Code Playgroud) django csrf django-rest-framework django-allauth django-rest-auth
我有一个对象数组(或只是数字),还有另一个数组,其中包含在任何情况下都不应从第一个数组中删除的所有对象。它看起来像这样:
-- Array of objects (just numbers for now)
Objects = {}
-- Array of objects that should always stay in the 'Objects' array
DontDestroyThese = {}
-- Populate the arrays
Objects[#Objects+1] = 1
Objects[#Objects+1] = 2
Objects[#Objects+1] = 3
Objects[#Objects+1] = 4
Objects[#Objects+1] = 5
DontDestroyThese[#DontDestroyThese+1] = 2
DontDestroyThese[#DontDestroyThese+1] = 5
Run Code Online (Sandbox Code Playgroud)
现在,我有一个名为的方法,destroy()该方法应该从数组中删除除Objects数组中包含的对象之外的所有对象DontDestroyThese。该方法看起来像这样:
function destroy()
for I = 1, #Objects do
if(DontDestroyThese[Objects[I]] ~= nil) then
print("Skipping " .. Objects[I])
else
Objects[I] = nil
end …Run Code Online (Sandbox Code Playgroud) 我将坐标存储为我的数据库中的纬度经度对.现在,我需要从给定的lat-long坐标中检索给定半径内的所有条目.例如,如果给定坐标48.796777,2.371140和距离20公里,它将检索距离该点20公里内的所有记录.
如果它提供任何简化或导致较少的CPU时间,则足够准确地计算点之间的"直线"距离,即不需要考虑地球的曲率.
如何用Django实现这一目标?更具体地说,如何为这样的查询构建视图(可能还有模型)?
我有两个类似的视图,它们返回相同的序列化响应。意见是这样的:
class GetFoos(generics.ListAPIView):
# init stuff here
def list(self, request):
queryset = Foo.objects.filter(owner = request.user)
serializer = FooSerializer(queryset, many = True)
return Response(serializer.data, status = status.HTTP_200_OK)
class GetFooResponses(generics.ListAPIView):
# init stuff here
def list(self, request):
queryset = FooResponse.objects.filter(owner = request.user)
serializer = FooResponseSerializer(queryset, many = True)
return Response(serializer.data, status = status.HTTP_200_OK)
Run Code Online (Sandbox Code Playgroud)
序列化程序是这样的:
class FooSerializer(serializers.ModelSerializer):
user = serializers.ProfileInfoSerializer(source = 'owner.userprofile', read_only = True)
class Meta:
model = Foo
fields = ('id', 'name', 'user')
class FooResponseSerializer(serializers.ModelSerializer):
id = serializers.ReadOnlyField(source = 'foo.id')
name …Run Code Online (Sandbox Code Playgroud)